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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 bool AdblockPlus::JsValue::IsFunction() const | 118 bool AdblockPlus::JsValue::IsFunction() const |
119 { | 119 { |
120 const JsContext context(*jsEngine); | 120 const JsContext context(*jsEngine); |
121 return UnwrapValue()->IsFunction(); | 121 return UnwrapValue()->IsFunction(); |
122 } | 122 } |
123 | 123 |
124 std::string AdblockPlus::JsValue::AsString() const | 124 std::string AdblockPlus::JsValue::AsString() const |
125 { | 125 { |
126 const JsContext context(*jsEngine); | 126 const JsContext context(*jsEngine); |
127 return Utils::FromV8String(UnwrapValue()); | 127 return Utils::FromV8String(jsEngine->GetIsolate(), UnwrapValue()); |
128 } | 128 } |
129 | 129 |
130 StringBuffer AdblockPlus::JsValue::AsStringBuffer() const | 130 StringBuffer AdblockPlus::JsValue::AsStringBuffer() const |
131 { | 131 { |
132 const JsContext context(*jsEngine); | 132 const JsContext context(*jsEngine); |
133 return Utils::StringBufferFromV8String(UnwrapValue()); | 133 return Utils::StringBufferFromV8String(jsEngine->GetIsolate(), UnwrapValue()); |
134 } | 134 } |
135 | 135 |
136 int64_t AdblockPlus::JsValue::AsInt() const | 136 int64_t AdblockPlus::JsValue::AsInt() const |
137 { | 137 { |
138 const JsContext context(*jsEngine); | 138 const JsContext context(*jsEngine); |
139 return UnwrapValue()->IntegerValue(); | 139 return UnwrapValue()->IntegerValue(); |
140 } | 140 } |
141 | 141 |
142 bool AdblockPlus::JsValue::AsBool() const | 142 bool AdblockPlus::JsValue::AsBool() const |
143 { | 143 { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 SetProperty(name, v8::Boolean::New(jsEngine->GetIsolate(), val)); | 233 SetProperty(name, v8::Boolean::New(jsEngine->GetIsolate(), val)); |
234 } | 234 } |
235 | 235 |
236 std::string AdblockPlus::JsValue::GetClass() const | 236 std::string AdblockPlus::JsValue::GetClass() const |
237 { | 237 { |
238 if (!IsObject()) | 238 if (!IsObject()) |
239 throw std::runtime_error("Cannot get constructor of a non-object"); | 239 throw std::runtime_error("Cannot get constructor of a non-object"); |
240 | 240 |
241 const JsContext context(*jsEngine); | 241 const JsContext context(*jsEngine); |
242 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); | 242 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); |
243 return Utils::FromV8String(obj->GetConstructorName()); | 243 return Utils::FromV8String(jsEngine->GetIsolate(), obj->GetConstructorName()); |
244 } | 244 } |
245 | 245 |
246 JsValue JsValue::Call(const JsValueList& params) const | 246 JsValue JsValue::Call(const JsValueList& params) const |
247 { | 247 { |
248 const JsContext context(*jsEngine); | 248 const JsContext context(*jsEngine); |
249 std::vector<v8::Local<v8::Value>> argv; | 249 std::vector<v8::Local<v8::Value>> argv; |
250 for (const auto& param : params) | 250 for (const auto& param : params) |
251 argv.push_back(param.UnwrapValue()); | 251 argv.push_back(param.UnwrapValue()); |
252 | 252 |
253 return Call(argv, context.GetV8Context()->Global()); | 253 return Call(argv, context.GetV8Context()->Global()); |
(...skipping 29 matching lines...) Expand all Loading... |
283 throw std::runtime_error("`this` pointer has to be an object"); | 283 throw std::runtime_error("`this` pointer has to be an object"); |
284 | 284 |
285 const JsContext context(*jsEngine); | 285 const JsContext context(*jsEngine); |
286 | 286 |
287 const v8::TryCatch tryCatch(jsEngine->GetIsolate()); | 287 const v8::TryCatch tryCatch(jsEngine->GetIsolate()); |
288 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); | 288 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); |
289 v8::Local<v8::Value> result = func->Call(thisObj, args.size(), | 289 v8::Local<v8::Value> result = func->Call(thisObj, args.size(), |
290 args.size() ? &args[0] : nullptr); | 290 args.size() ? &args[0] : nullptr); |
291 | 291 |
292 if (tryCatch.HasCaught()) | 292 if (tryCatch.HasCaught()) |
293 throw JsError(tryCatch.Exception(), tryCatch.Message()); | 293 throw JsError(jsEngine->GetIsolate(), tryCatch.Exception(), tryCatch.Message
()); |
294 | 294 |
295 return JsValue(jsEngine, result); | 295 return JsValue(jsEngine, result); |
296 } | 296 } |
OLD | NEW |