OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return result; | 139 return result; |
140 } | 140 } |
141 | 141 |
142 | 142 |
143 AdblockPlus::JsValuePtr AdblockPlus::JsValue::GetProperty(const std::string& nam
e) const | 143 AdblockPlus::JsValuePtr AdblockPlus::JsValue::GetProperty(const std::string& nam
e) const |
144 { | 144 { |
145 if (!IsObject()) | 145 if (!IsObject()) |
146 throw new std::runtime_error("Attempting to get property of a non-object"); | 146 throw new std::runtime_error("Attempting to get property of a non-object"); |
147 | 147 |
148 const JsContext context(jsEngine); | 148 const JsContext context(jsEngine); |
149 v8::Local<v8::String> property = Utils::ToV8String(name); | 149 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->isolate, name); |
150 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); | 150 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); |
151 return JsValuePtr(new JsValue(jsEngine, obj->Get(property))); | 151 return JsValuePtr(new JsValue(jsEngine, obj->Get(property))); |
152 } | 152 } |
153 | 153 |
154 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::V
alue> val) | 154 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::V
alue> val) |
155 { | 155 { |
156 if (!IsObject()) | 156 if (!IsObject()) |
157 throw new std::runtime_error("Attempting to set property on a non-object"); | 157 throw new std::runtime_error("Attempting to set property on a non-object"); |
158 | 158 |
159 v8::Local<v8::String> property = Utils::ToV8String(name); | 159 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->isolate, name); |
160 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); | 160 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); |
161 obj->Set(property, val); | 161 obj->Set(property, val); |
162 } | 162 } |
163 | 163 |
164 v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const | 164 v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const |
165 { | 165 { |
166 return v8::Local<v8::Value>::New(jsEngine->isolate, value); | 166 return v8::Local<v8::Value>::New(jsEngine->isolate, value); |
167 } | 167 } |
168 | 168 |
169 void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::strin
g& val) | 169 void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::strin
g& val) |
170 { | 170 { |
171 const JsContext context(jsEngine); | 171 const JsContext context(jsEngine); |
172 SetProperty(name, Utils::ToV8String(val)); | 172 SetProperty(name, Utils::ToV8String(jsEngine->isolate, val)); |
173 } | 173 } |
174 | 174 |
175 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) | 175 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) |
176 { | 176 { |
177 const JsContext context(jsEngine); | 177 const JsContext context(jsEngine); |
178 SetProperty(name, v8::Number::New(val)); | 178 SetProperty(name, v8::Number::New(jsEngine->isolate, val)); |
179 } | 179 } |
180 | 180 |
181 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValuePtr
& val) | 181 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValuePtr
& val) |
182 { | 182 { |
183 const JsContext context(jsEngine); | 183 const JsContext context(jsEngine); |
184 SetProperty(name, val->UnwrapValue()); | 184 SetProperty(name, val->UnwrapValue()); |
185 } | 185 } |
186 | 186 |
187 void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val) | 187 void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val) |
188 { | 188 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 const v8::TryCatch tryCatch; | 222 const v8::TryCatch tryCatch; |
223 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); | 223 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); |
224 v8::Local<v8::Value> result = func->Call(thisObj, argv.size(), | 224 v8::Local<v8::Value> result = func->Call(thisObj, argv.size(), |
225 argv.size() ? &argv.front() : 0); | 225 argv.size() ? &argv.front() : 0); |
226 | 226 |
227 if (tryCatch.HasCaught()) | 227 if (tryCatch.HasCaught()) |
228 throw JsError(tryCatch.Exception(), tryCatch.Message()); | 228 throw JsError(tryCatch.Exception(), tryCatch.Message()); |
229 | 229 |
230 return JsValuePtr(new JsValue(jsEngine, result)); | 230 return JsValuePtr(new JsValue(jsEngine, result)); |
231 } | 231 } |
OLD | NEW |