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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/GlobalJsObject.h ('k') | src/JsEngine.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/GlobalJsObject.cpp
===================================================================
--- a/src/GlobalJsObject.cpp
+++ b/src/GlobalJsObject.cpp
@@ -63,29 +63,19 @@ namespace
// We should actually return the timer ID here, which could be
// used via clearTimeout(). But since we don't seem to need
// clearTimeout(), we can save that for later.
return v8::Undefined();
}
}
-v8::Handle<v8::ObjectTemplate> GlobalJsObject::Create(
- JsEngine& jsEngine)
+JsValuePtr GlobalJsObject::Setup(JsEngine& jsEngine, JsValuePtr obj)
{
- const v8::Locker locker(v8::Isolate::GetCurrent());
- v8::HandleScope handleScope;
- const v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
- const v8::Handle<v8::FunctionTemplate> setTimeoutFunction =
- v8::FunctionTemplate::New(SetTimeoutCallback,
- v8::External::New(&jsEngine));
- global->Set(v8::String::New("setTimeout"), setTimeoutFunction);
- const v8::Handle<v8::ObjectTemplate> fileSystemObject =
- FileSystemJsObject::Create(jsEngine);
- global->Set(v8::String::New("_fileSystem"), fileSystemObject);
- const v8::Handle<v8::ObjectTemplate> webRequestObject =
- WebRequestJsObject::Create(jsEngine);
- global->Set(v8::String::New("_webRequest"), webRequestObject);
- const v8::Handle<v8::ObjectTemplate> consoleObject =
- ConsoleJsObject::Create(jsEngine);
- global->Set(v8::String::New("console"), consoleObject);
- return handleScope.Close(global);
+ obj->SetProperty("setTimeout", jsEngine.NewCallback(::SetTimeoutCallback));
+ obj->SetProperty("_fileSystem",
+ FileSystemJsObject::Setup(jsEngine, jsEngine.NewObject()));
+ obj->SetProperty("_webRequest",
+ WebRequestJsObject::Setup(jsEngine, jsEngine.NewObject()));
+ obj->SetProperty("console",
+ ConsoleJsObject::Setup(jsEngine, jsEngine.NewObject()));
+ return obj;
}
« 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