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

Delta Between Two Patch Sets: src/GlobalJsObject.cpp

Issue 10184021: Some refactoring of global JavaScript objects (Closed)
Left Patch Set: Created April 15, 2013, 2:54 p.m.
Right Patch Set: Unbitrotted patch Created April 16, 2013, 3:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/GlobalJsObject.h ('k') | src/JsEngine.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include <vector> 1 #include <vector>
2 #include <stdexcept> 2 #include <stdexcept>
3 3
4 #include <AdblockPlus/JsEngine.h> 4 #include <AdblockPlus/JsEngine.h>
5 #include <AdblockPlus/JsValue.h> 5 #include <AdblockPlus/JsValue.h>
6 #include "ConsoleJsObject.h"
7 #include "FileSystemJsObject.h"
6 #include "GlobalJsObject.h" 8 #include "GlobalJsObject.h"
7 #include "ConsoleJsObject.h" 9 #include "ConsoleJsObject.h"
8 #include "WebRequestJsObject.h" 10 #include "WebRequestJsObject.h"
9 #include "Thread.h" 11 #include "Thread.h"
10 12
11 using namespace AdblockPlus; 13 using namespace AdblockPlus;
12 14
13 namespace 15 namespace
14 { 16 {
15 class TimeoutThread : public Thread 17 class TimeoutThread : public Thread
(...skipping 12 matching lines...) Expand all
28 delay = arguments[1]->AsInt(); 30 delay = arguments[1]->AsInt();
29 for (size_t i = 2; i < arguments.size(); i++) 31 for (size_t i = 2; i < arguments.size(); i++)
30 functionArguments.push_back(arguments[i]); 32 functionArguments.push_back(arguments[i]);
31 } 33 }
32 34
33 void Run() 35 void Run()
34 { 36 {
35 Sleep(delay); 37 Sleep(delay);
36 38
37 function->Call(functionArguments); 39 function->Call(functionArguments);
38 delete this;
39 } 40 }
40 41
41 private: 42 private:
42 typedef v8::Persistent<v8::Value> Value;
43 typedef std::vector<Value> Values;
44
45 JsValuePtr function; 43 JsValuePtr function;
46 int delay; 44 int delay;
47 JsValueList functionArguments; 45 JsValueList functionArguments;
48 }; 46 };
49 47
50 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) 48 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments)
51 { 49 {
52 TimeoutThread* timeoutThread; 50 TimeoutThread* timeoutThread;
53 try 51 try
54 { 52 {
(...skipping 14 matching lines...) Expand all
69 return v8::Undefined(); 67 return v8::Undefined();
70 } 68 }
71 } 69 }
72 70
73 v8::Handle<v8::ObjectTemplate> GlobalJsObject::Create( 71 v8::Handle<v8::ObjectTemplate> GlobalJsObject::Create(
74 JsEngine& jsEngine) 72 JsEngine& jsEngine)
75 { 73 {
76 const v8::Locker locker(v8::Isolate::GetCurrent()); 74 const v8::Locker locker(v8::Isolate::GetCurrent());
77 v8::HandleScope handleScope; 75 v8::HandleScope handleScope;
78 const v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 76 const v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
79 const v8::Handle<v8::ObjectTemplate> console =
80 AdblockPlus::ConsoleJsObject::Create(jsEngine);
81 global->Set(v8::String::New("console"), console);
82 const v8::Handle<v8::FunctionTemplate> setTimeoutFunction = 77 const v8::Handle<v8::FunctionTemplate> setTimeoutFunction =
83 v8::FunctionTemplate::New(::SetTimeoutCallback, 78 v8::FunctionTemplate::New(SetTimeoutCallback,
84 v8::External::New(&jsEngine)); 79 v8::External::New(&jsEngine));
85 global->Set(v8::String::New("setTimeout"), setTimeoutFunction); 80 global->Set(v8::String::New("setTimeout"), setTimeoutFunction);
86 const v8::Handle<v8::ObjectTemplate> request = 81 const v8::Handle<v8::ObjectTemplate> fileSystemObject =
87 AdblockPlus::WebRequestJsObject::Create(jsEngine); 82 FileSystemJsObject::Create(jsEngine);
88 global->Set(v8::String::New("_webRequest"), request); 83 global->Set(v8::String::New("_fileSystem"), fileSystemObject);
84 const v8::Handle<v8::ObjectTemplate> webRequestObject =
85 WebRequestJsObject::Create(jsEngine);
86 global->Set(v8::String::New("_webRequest"), webRequestObject);
87 const v8::Handle<v8::ObjectTemplate> consoleObject =
88 ConsoleJsObject::Create(jsEngine);
89 global->Set(v8::String::New("console"), consoleObject);
89 return handleScope.Close(global); 90 return handleScope.Close(global);
90 } 91 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld