| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 (const IFileSystem::StatResult& statResult, const std::string& error) | 176 (const IFileSystem::StatResult& statResult, const std::string& error) |
| 177 { | 177 { |
| 178 auto jsEngine = weakJsEngine.lock(); | 178 auto jsEngine = weakJsEngine.lock(); |
| 179 if (!jsEngine) | 179 if (!jsEngine) |
| 180 return; | 180 return; |
| 181 | 181 |
| 182 const JsContext context(*jsEngine); | 182 const JsContext context(*jsEngine); |
| 183 auto result = jsEngine->NewObject(); | 183 auto result = jsEngine->NewObject(); |
| 184 | 184 |
| 185 result.SetProperty("exists", statResult.exists); | 185 result.SetProperty("exists", statResult.exists); |
| 186 result.SetProperty("isFile", statResult.isFile); | |
| 187 result.SetProperty("isDirectory", statResult.isDirectory); | |
| 188 result.SetProperty("lastModified", statResult.lastModified); | 186 result.SetProperty("lastModified", statResult.lastModified); |
| 189 if (!error.empty()) | 187 if (!error.empty()) |
| 190 result.SetProperty("error", error); | 188 result.SetProperty("error", error); |
| 191 | 189 |
| 192 JsValueList params; | 190 JsValueList params; |
| 193 params.push_back(result); | 191 params.push_back(result); |
| 194 jsEngine->TakeJsValues(weakCallback)[0].Call(params); | 192 jsEngine->TakeJsValues(weakCallback)[0].Call(params); |
| 195 }); | 193 }); |
| 196 } | 194 } |
| 197 | |
| 198 void ResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) | |
| 199 { | |
| 200 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | |
| 201 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | |
| 202 | |
| 203 v8::Isolate* isolate = arguments.GetIsolate(); | |
| 204 if (converted.size() != 1) | |
| 205 return ThrowExceptionInJS(isolate, "_fileSystem.resolve requires 1 paramet
er"); | |
| 206 | |
| 207 std::string resolved = jsEngine->GetPlatform().GetFileSystem().Resolve(conve
rted[0].AsString()); | |
| 208 arguments.GetReturnValue().Set(Utils::ToV8String(isolate, resolved)); | |
| 209 } | |
| 210 } | 195 } |
| 211 | 196 |
| 212 | 197 |
| 213 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj) | 198 JsValue& FileSystemJsObject::Setup(JsEngine& jsEngine, JsValue& obj) |
| 214 { | 199 { |
| 215 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback)); | 200 obj.SetProperty("read", jsEngine.NewCallback(::ReadCallback)); |
| 216 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback)); | 201 obj.SetProperty("write", jsEngine.NewCallback(::WriteCallback)); |
| 217 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback)); | 202 obj.SetProperty("move", jsEngine.NewCallback(::MoveCallback)); |
| 218 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback)); | 203 obj.SetProperty("remove", jsEngine.NewCallback(::RemoveCallback)); |
| 219 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback)); | 204 obj.SetProperty("stat", jsEngine.NewCallback(::StatCallback)); |
| 220 obj.SetProperty("resolve", jsEngine.NewCallback(::ResolveCallback)); | |
| 221 return obj; | 205 return obj; |
| 222 } | 206 } |
| OLD | NEW |