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

Side by Side Diff: src/ConsoleJsObject.cpp

Issue 10184021: Some refactoring of global JavaScript objects (Closed)
Patch Set: Created April 15, 2013, 2:54 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
« no previous file with comments | « src/ConsoleJsObject.h ('k') | src/GlobalJsObject.h » ('j') | 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/JsEngine.h>
2 #include <AdblockPlus/JsValue.h>
1 #include <AdblockPlus/ErrorCallback.h> 3 #include <AdblockPlus/ErrorCallback.h>
2 #include <sstream> 4 #include <sstream>
3 5
4 #include "ConsoleJsObject.h" 6 #include "ConsoleJsObject.h"
5 7
6 namespace 8 namespace
7 { 9 {
8 v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments) 10 v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments)
9 { 11 {
12 AdblockPlus::JsEngine& jsEngine = AdblockPlus::JsEngine::FromArguments(argum ents);
13 const AdblockPlus::JsEngine::Context context(jsEngine);
14 AdblockPlus::JsValueList converted = jsEngine.ConvertArguments(arguments);
15
10 std::stringstream message; 16 std::stringstream message;
11 const v8::HandleScope handleScope; 17 for (size_t i = 0; i < converted.size(); i++)
12 for (int i = 0; i < arguments.Length(); i++) 18 message << converted[i]->AsString();
13 { 19
14 const v8::Handle<v8::Value> argument = arguments[i]; 20 (jsEngine.GetErrorCallback())(message.str());
15 const v8::String::Utf8Value value(argument);
16 message << *value;
17 }
18 const v8::Handle<const v8::External> external =
19 v8::Handle<const v8::External>::Cast(arguments.Data());
20 AdblockPlus::ErrorCallback* const errorCallback =
21 static_cast<AdblockPlus::ErrorCallback*>(external->Value());
22 (*errorCallback)(message.str());
23 return v8::Undefined(); 21 return v8::Undefined();
24 } 22 }
25 23
26 v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments) 24 v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments)
27 { 25 {
28 return v8::Undefined(); 26 return v8::Undefined();
29 } 27 }
30 } 28 }
31 29
32 v8::Handle<v8::ObjectTemplate> AdblockPlus::ConsoleJsObject::Create( 30 v8::Handle<v8::ObjectTemplate> AdblockPlus::ConsoleJsObject::Create(
33 AdblockPlus::ErrorCallback& errorCallback) 31 AdblockPlus::JsEngine& jsEngine)
34 { 32 {
35 v8::HandleScope handleScope; 33 v8::HandleScope handleScope;
36 const v8::Handle<v8::ObjectTemplate> console = v8::ObjectTemplate::New(); 34 const v8::Handle<v8::ObjectTemplate> console = v8::ObjectTemplate::New();
37 const v8::Handle<v8::FunctionTemplate> errorFunction = 35 const v8::Handle<v8::FunctionTemplate> errorFunction =
38 v8::FunctionTemplate::New(::ErrorCallback, 36 v8::FunctionTemplate::New(::ErrorCallback,
39 v8::External::New(&errorCallback)); 37 v8::External::New(&jsEngine));
40 console->Set(v8::String::New("error"), errorFunction); 38 console->Set(v8::String::New("error"), errorFunction);
41 const v8::Handle<v8::FunctionTemplate> traceFunction = 39 const v8::Handle<v8::FunctionTemplate> traceFunction =
42 v8::FunctionTemplate::New(TraceCallback); 40 v8::FunctionTemplate::New(TraceCallback);
43 console->Set(v8::String::New("trace"), traceFunction); 41 console->Set(v8::String::New("trace"), traceFunction);
44 return handleScope.Close(console); 42 return handleScope.Close(console);
45 } 43 }
OLDNEW
« no previous file with comments | « src/ConsoleJsObject.h ('k') | src/GlobalJsObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld