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

Side by Side Diff: src/ConsoleJsObject.cpp

Issue 10305024: Simplify context setup, set properties on the global object directly instead of using templates (Closed)
Patch Set: Created April 18, 2013, 6:26 a.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/FileSystemJsObject.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> 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 }
OLDNEW
« no previous file with comments | « src/ConsoleJsObject.h ('k') | src/FileSystemJsObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld