Warning of app not ready in screen module

This commit is contained in:
Cheng Zhao 2015-01-14 16:37:48 -08:00
parent e8f1f6819c
commit c6fb645f6b
3 changed files with 12 additions and 6 deletions

View file

@ -107,15 +107,21 @@ mate::ObjectTemplateBuilder Screen::GetObjectTemplateBuilder(
}
// static
mate::Handle<Screen> Screen::Create(v8::Isolate* isolate) {
v8::Handle<v8::Value> Screen::Create(v8::Isolate* isolate) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate, "Can not initialize \"screen\" module before app is ready")));
return v8::Undefined(isolate);
}
gfx::Screen* screen = gfx::Screen::GetNativeScreen();
if (!screen) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate, "Failed to get screen information")));
return mate::Handle<Screen>();
return v8::Undefined(isolate);
}
return CreateHandle(isolate, new Screen(screen));
return mate::CreateHandle(isolate, new Screen(screen)).ToV8();
}
} // namespace api

View file

@ -24,7 +24,7 @@ namespace api {
class Screen : public mate::EventEmitter,
public gfx::DisplayObserver {
public:
static mate::Handle<Screen> Create(v8::Isolate* isolate);
static v8::Handle<v8::Value> Create(v8::Isolate* isolate);
protected:
explicit Screen(gfx::Screen* screen);

View file

@ -83,12 +83,12 @@ struct Converter<gfx::Display::TouchSupport> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
const gfx::Display::TouchSupport& val) {
switch (val) {
case gfx::Display::TOUCH_SUPPORT_UNKNOWN:
return StringToV8(isolate, "unknown");
case gfx::Display::TOUCH_SUPPORT_AVAILABLE:
return StringToV8(isolate, "available");
case gfx::Display::TOUCH_SUPPORT_UNAVAILABLE:
return StringToV8(isolate, "unavailable");
default:
return StringToV8(isolate, "unknown");
}
}
};