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

Side by Side Diff: src/GlobalJsObject.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/GlobalJsObject.h ('k') | src/JsEngine.cpp » ('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 <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" 6 #include "ConsoleJsObject.h"
7 #include "FileSystemJsObject.h" 7 #include "FileSystemJsObject.h"
8 #include "GlobalJsObject.h" 8 #include "GlobalJsObject.h"
9 #include "ConsoleJsObject.h" 9 #include "ConsoleJsObject.h"
10 #include "WebRequestJsObject.h" 10 #include "WebRequestJsObject.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 timeoutThread->Start(); 62 timeoutThread->Start();
63 63
64 // We should actually return the timer ID here, which could be 64 // We should actually return the timer ID here, which could be
65 // used via clearTimeout(). But since we don't seem to need 65 // used via clearTimeout(). But since we don't seem to need
66 // clearTimeout(), we can save that for later. 66 // clearTimeout(), we can save that for later.
67 return v8::Undefined(); 67 return v8::Undefined();
68 } 68 }
69 } 69 }
70 70
71 v8::Handle<v8::ObjectTemplate> GlobalJsObject::Create( 71 JsValuePtr GlobalJsObject::Setup(JsEngine& jsEngine, JsValuePtr obj)
72 JsEngine& jsEngine)
73 { 72 {
74 const v8::Locker locker(v8::Isolate::GetCurrent()); 73 obj->SetProperty("setTimeout", jsEngine.NewCallback(::SetTimeoutCallback));
75 v8::HandleScope handleScope; 74 obj->SetProperty("_fileSystem",
76 const v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 75 FileSystemJsObject::Setup(jsEngine, jsEngine.NewObject()));
77 const v8::Handle<v8::FunctionTemplate> setTimeoutFunction = 76 obj->SetProperty("_webRequest",
78 v8::FunctionTemplate::New(SetTimeoutCallback, 77 WebRequestJsObject::Setup(jsEngine, jsEngine.NewObject()));
79 v8::External::New(&jsEngine)); 78 obj->SetProperty("console",
80 global->Set(v8::String::New("setTimeout"), setTimeoutFunction); 79 ConsoleJsObject::Setup(jsEngine, jsEngine.NewObject()));
81 const v8::Handle<v8::ObjectTemplate> fileSystemObject = 80 return obj;
82 FileSystemJsObject::Create(jsEngine);
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);
90 return handleScope.Close(global);
91 } 81 }
OLDNEW
« no previous file with comments | « src/GlobalJsObject.h ('k') | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld