OLD | NEW |
1 #include <AdblockPlus/JsEngine.h> | 1 #include <AdblockPlus/JsEngine.h> |
2 #include <AdblockPlus/JsValue.h> | 2 #include <AdblockPlus/JsValue.h> |
3 #include <AdblockPlus/ErrorCallback.h> | 3 #include <AdblockPlus/ErrorCallback.h> |
4 #include <sstream> | 4 #include <sstream> |
5 | 5 |
6 #include "ConsoleJsObject.h" | 6 #include "ConsoleJsObject.h" |
7 | 7 |
8 namespace | 8 namespace |
9 { | 9 { |
10 v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments) | 10 v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments) |
11 { | 11 { |
12 AdblockPlus::JsEngine& jsEngine = AdblockPlus::JsEngine::FromArguments(argum
ents); | 12 AdblockPlus::JsEngine& jsEngine = AdblockPlus::JsEngine::FromArguments(argum
ents); |
13 const AdblockPlus::JsEngine::Context context(jsEngine); | 13 const AdblockPlus::JsEngine::Context context(jsEngine); |
14 AdblockPlus::JsValueList converted = jsEngine.ConvertArguments(arguments); | 14 AdblockPlus::JsValueList converted = jsEngine.ConvertArguments(arguments); |
15 | 15 |
16 std::stringstream message; | 16 std::stringstream message; |
17 for (size_t i = 0; i < converted.size(); i++) | 17 for (size_t i = 0; i < converted.size(); i++) |
18 message << converted[i]->AsString(); | 18 message << converted[i]->AsString(); |
19 | 19 |
20 (jsEngine.GetErrorCallback())(message.str()); | 20 (jsEngine.GetErrorCallback())(message.str()); |
21 return v8::Undefined(); | 21 return v8::Undefined(); |
22 } | 22 } |
23 | 23 |
24 v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments) | 24 v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments) |
25 { | 25 { |
26 return v8::Undefined(); | 26 return v8::Undefined(); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 v8::Handle<v8::ObjectTemplate> AdblockPlus::ConsoleJsObject::Create( | 30 AdblockPlus::JsValuePtr AdblockPlus::ConsoleJsObject::Setup( |
31 AdblockPlus::JsEngine& jsEngine) | 31 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValuePtr obj) |
32 { | 32 { |
33 v8::HandleScope handleScope; | 33 obj->SetProperty("error", jsEngine.NewCallback(::ErrorCallback)); |
34 const v8::Handle<v8::ObjectTemplate> console = v8::ObjectTemplate::New(); | 34 obj->SetProperty("trace", jsEngine.NewCallback(::TraceCallback)); |
35 const v8::Handle<v8::FunctionTemplate> errorFunction = | 35 return obj; |
36 v8::FunctionTemplate::New(::ErrorCallback, | |
37 v8::External::New(&jsEngine)); | |
38 console->Set(v8::String::New("error"), errorFunction); | |
39 const v8::Handle<v8::FunctionTemplate> traceFunction = | |
40 v8::FunctionTemplate::New(TraceCallback); | |
41 console->Set(v8::String::New("trace"), traceFunction); | |
42 return handleScope.Close(console); | |
43 } | 36 } |
OLD | NEW |