Skip to content
Browse files

remove AppjsEmitter and just use process

  • Loading branch information...
1 parent b7992f8 commit a713dec6526afd0fa39573280cbb75c4bc147134 @Benvie Benvie committed Aug 10, 2012
Showing with 10 additions and 34 deletions.
  1. +3 −0 lib/index.js
  2. +0 −25 src/appjs_app.cpp
  3. +1 −1 src/appjs_app.h
  4. +2 −3 src/includes/cef_handler.cpp
  5. +4 −5 src/includes/cef_scheme_handler.cpp
View
3 lib/index.js
@@ -78,6 +78,9 @@ decorate(App.prototype, [
function serveFilesFrom(root){
this.router.use(staticRouter(root));
return this;
+ },
+ function on(type, listener){
+ process.on('appjs-'+type, listener.bind(this));
}
]);
View
25 src/appjs_app.cpp
@@ -17,7 +17,6 @@ Persistent<Function> App::constructor;
void App::Init() {
DECLARE_CONSTRUCTOR("App");
- DECLARE_PROTOTYPE_METHOD("on",On);
DECLARE_PROTOTYPE_METHOD("createWindow",CreateWindow2);
DECLARE_CLASS_FUNCTION(screenWidth, ScreenWidth);
DECLARE_CLASS_FUNCTION(screenHeight, ScreenHeight);
@@ -40,15 +39,6 @@ Handle<Value> App::NewInstance(const Arguments& args) {
Handle<Value> argv[1] = { args[0] };
Local<Object> instance = constructor->NewInstance(1, argv);
- // get the events.EventEmitter constructor
- Local<Object> global = Context::GetCurrent()->Global();
- Handle<Object> process = global->Get(String::NewSymbol("process"))->ToObject();
- Local<Function> EventEmitter = Local<Function>::Cast(process->Get(String::NewSymbol("EventEmitter")));
-
- // create process.AppjsEmitter object
- Handle<Object> AppjsEmitter = EventEmitter->NewInstance();
- process->Set(String::NewSymbol("AppjsEmitter"), AppjsEmitter);
-
return scope.Close(instance);
}
@@ -69,20 +59,5 @@ Handle<Value> App::ScreenHeight(const Arguments& args) {
return scope.Close(height);
}
-Handle<Value> App::On(const Arguments& args) {
- HandleScope scope;
-
- Local<Object> global = Context::GetCurrent()->Global();
- Local<Object> process = global->Get(String::NewSymbol("process"))->ToObject();
- Local<Object> Emitter = Local<Object>::Cast(process->Get(String::NewSymbol("AppjsEmitter")));
- Local<Function> On = Local<Function>::Cast(Emitter->Get(String::NewSymbol("on")));
-
- Handle<Value> argv[2] = { args[0] , args[1] };
- On->Call(Emitter, 2, argv);
-
- return scope.Close(args.This());
-}
-
-
} /* appjs */
View
2 src/appjs_app.h
@@ -14,7 +14,7 @@ class App : public node::ObjectWrap {
DEFINE_CLASS_FUNCTION(ScreenWidth);
DEFINE_CLASS_FUNCTION(ScreenHeight);
DEFINE_PROTOTYPE_METHOD(CreateWindow2);
- DEFINE_PROTOTYPE_METHOD(On);
+
static bool initialized_;
};
View
5 src/includes/cef_handler.cpp
@@ -73,9 +73,8 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
if (!browser->IsPopup() && --windowCount == 0) {
Local<Object> global = Context::GetCurrent()->Global();
- Local<Object> process = global->Get(String::NewSymbol("process"))->ToObject();
- Local<Object> emitter = Local<Object>::Cast(process->Get(String::NewSymbol("AppjsEmitter")));
- Handle<Value> exitArgv[1] = {String::New("exit")};
+ Local<Object> emitter = global->Get(String::NewSymbol("process"))->ToObject();
+ Handle<Value> exitArgv[1] = {String::New("appjs-exit")};
node::MakeCallback(emitter,"emit",1,exitArgv);
Cef::Shutdown();
mainBrowserHandle = NULL;
View
9 src/includes/cef_scheme_handler.cpp
@@ -36,8 +36,7 @@ void AppjsSchemeHandler::Execute(CefThreadId threadId) {
HandleScope scope;
Local<Object> global = Context::GetCurrent()->Global();
- Local<Object> process = global->Get(String::NewSymbol("process"))->ToObject();
- Local<Object> emitter = Local<Object>::Cast(process->Get(String::NewSymbol("AppjsEmitter")));
+ Local<Object> emitter = global->Get(String::NewSymbol("process"))->ToObject();
const int argc = 3;
@@ -99,7 +98,7 @@ void AppjsSchemeHandler::Execute(CefThreadId threadId) {
req->Set(String::NewSymbol("headers"),headers);
req->Set(String::NewSymbol("files"),files);
- Handle<Value> argv[argc] = {String::New("request"),req,cb};
+ Handle<Value> argv[argc] = {String::New("appjs-request"),req,cb};
node::MakeCallback(emitter,"emit",argc,argv);
}
@@ -113,8 +112,8 @@ Handle<Value> AppjsSchemeHandler::NodeCallback(const Arguments& args) {
AutoLock lock_scope(me);
me->status_ = args[0]->NumberValue();
- me->status_text_ = appjs::V8StringToChar(args[1]->ToString());
- me->mime_type_ = appjs::V8StringToChar(args[2]->ToString());
+ me->status_text_ = V8StringToChar(args[1]->ToString());
+ me->mime_type_ = V8StringToChar(args[2]->ToString());
me->data_ = node::Buffer::Data(args[3]->ToObject());
me->data_length_ = node::Buffer::Length(args[3]->ToObject());

0 comments on commit a713dec

Please sign in to comment.
Something went wrong with that request. Please try again.