OLD | NEW |
1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
2 | 2 |
3 namespace | 3 namespace |
4 { | 4 { |
5 std::string fromV8String(v8::Handle<v8::Value> value) | 5 std::string fromV8String(v8::Handle<v8::Value> value) |
6 { | 6 { |
7 v8::String::Utf8Value stringValue(value); | 7 v8::String::Utf8Value stringValue(value); |
8 if (stringValue.length()) | 8 if (stringValue.length()) |
9 return std::string(*stringValue, stringValue.length()); | 9 return std::string(*stringValue, stringValue.length()); |
10 else | 10 else |
11 return std::string(); | 11 return std::string(); |
12 } | 12 } |
13 | 13 |
14 v8::Local<v8::String> toV8String(const std::string& str) | 14 v8::Local<v8::String> toV8String(const std::string& str) |
15 { | 15 { |
16 return v8::String::New(str.c_str(), str.length()); | 16 return v8::String::New(str.c_str(), str.length()); |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 AdblockPlus::JsValue::JsValue(AdblockPlus::JsEnginePtr jsEngine, | 20 AdblockPlus::JsValue::JsValue(AdblockPlus::JsEnginePtr jsEngine, |
21 v8::Handle<v8::Value> value) | 21 v8::Handle<v8::Value> value) |
22 : jsEngine(jsEngine), | 22 : jsEngine(jsEngine), |
23 value(v8::Persistent<v8::Value>::New(jsEngine->isolate, value)) | 23 value(v8::Persistent<v8::Value>::New(jsEngine->isolate, value)) |
24 { | 24 { |
25 } | 25 } |
26 | 26 |
| 27 AdblockPlus::JsValue::JsValue(AdblockPlus::JsValuePtr value) |
| 28 : jsEngine(value->jsEngine), |
| 29 value(v8::Persistent<v8::Value>::New(jsEngine->isolate, value->value)) |
| 30 { |
| 31 } |
| 32 |
27 AdblockPlus::JsValue::~JsValue() | 33 AdblockPlus::JsValue::~JsValue() |
28 { | 34 { |
29 value.Dispose(jsEngine->isolate); | 35 value.Dispose(jsEngine->isolate); |
30 } | 36 } |
31 | 37 |
32 bool AdblockPlus::JsValue::IsUndefined() const | 38 bool AdblockPlus::JsValue::IsUndefined() const |
33 { | 39 { |
34 const JsEngine::Context context(jsEngine); | 40 const JsEngine::Context context(jsEngine); |
35 return value->IsUndefined(); | 41 return value->IsUndefined(); |
36 } | 42 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 const v8::TryCatch tryCatch; | 211 const v8::TryCatch tryCatch; |
206 v8::Persistent<v8::Function> func = v8::Persistent<v8::Function>::Cast(value); | 212 v8::Persistent<v8::Function> func = v8::Persistent<v8::Function>::Cast(value); |
207 v8::Local<v8::Value> result = func->Call(thisObj, argc, argv); | 213 v8::Local<v8::Value> result = func->Call(thisObj, argc, argv); |
208 delete argv; | 214 delete argv; |
209 | 215 |
210 if (tryCatch.HasCaught()) | 216 if (tryCatch.HasCaught()) |
211 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); | 217 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); |
212 | 218 |
213 return JsValuePtr(new JsValue(jsEngine, result)); | 219 return JsValuePtr(new JsValue(jsEngine, result)); |
214 } | 220 } |
OLD | NEW |