Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/JsValue.cpp

Issue 10190024: Use our own isolate instead of the default one (Closed)
Patch Set: Created April 17, 2013, 1:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« include/AdblockPlus/JsEngine.h ('K') | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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::JsEngine& jsEngine, 20 AdblockPlus::JsValue::JsValue(AdblockPlus::JsEngine& 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() 27 AdblockPlus::JsValue::~JsValue()
28 { 28 {
29 const JsEngine::Context context(jsEngine);
29 value.Dispose(jsEngine.isolate); 30 value.Dispose(jsEngine.isolate);
30 } 31 }
31 32
32 bool AdblockPlus::JsValue::IsUndefined() const 33 bool AdblockPlus::JsValue::IsUndefined() const
33 { 34 {
34 const JsEngine::Context context(jsEngine); 35 const JsEngine::Context context(jsEngine);
35 return value->IsUndefined(); 36 return value->IsUndefined();
36 } 37 }
37 38
38 bool AdblockPlus::JsValue::IsNull() const 39 bool AdblockPlus::JsValue::IsNull() const
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 const v8::TryCatch tryCatch; 206 const v8::TryCatch tryCatch;
206 v8::Persistent<v8::Function> func = v8::Persistent<v8::Function>::Cast(value); 207 v8::Persistent<v8::Function> func = v8::Persistent<v8::Function>::Cast(value);
207 v8::Local<v8::Value> result = func->Call(thisObj, argc, argv); 208 v8::Local<v8::Value> result = func->Call(thisObj, argc, argv);
208 delete argv; 209 delete argv;
209 210
210 if (tryCatch.HasCaught()) 211 if (tryCatch.HasCaught())
211 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); 212 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message());
212 213
213 return JsValuePtr(new JsValue(jsEngine, result)); 214 return JsValuePtr(new JsValue(jsEngine, result));
214 } 215 }
OLDNEW
« include/AdblockPlus/JsEngine.h ('K') | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld