Browse Source

Added Image#complete getter

v1.x
Tj Holowaychuk 14 years ago
parent
commit
db4c00ce42
  1. 13
      src/Image.cc
  2. 1
      src/Image.h

13
src/Image.cc

@ -22,6 +22,7 @@ Image::Initialize(Handle<Object> target) {
Local<ObjectTemplate> proto = t->PrototypeTemplate(); Local<ObjectTemplate> proto = t->PrototypeTemplate();
NODE_SET_PROTOTYPE_METHOD(t, "inspect", Inspect); NODE_SET_PROTOTYPE_METHOD(t, "inspect", Inspect);
proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc); proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc);
proto->SetAccessor(String::NewSymbol("complete"), GetComplete);
proto->SetAccessor(String::NewSymbol("onload"), GetOnload, SetOnload); proto->SetAccessor(String::NewSymbol("onload"), GetOnload, SetOnload);
proto->SetAccessor(String::NewSymbol("onerror"), GetOnerror, SetOnerror); proto->SetAccessor(String::NewSymbol("onerror"), GetOnerror, SetOnerror);
target->Set(String::NewSymbol("Image"), t->GetFunction()); target->Set(String::NewSymbol("Image"), t->GetFunction());
@ -56,6 +57,16 @@ Image::Inspect(const Arguments &args) {
return scope.Close(str); return scope.Close(str);
} }
/*
* Get complete boolean.
*/
Handle<Value>
Image::GetComplete(Local<String>, const AccessorInfo &info) {
Image *img = ObjectWrap::Unwrap<Image>(info.This());
return Boolean::New(img->complete);
}
/* /*
* Get src path. * Get src path.
*/ */
@ -174,6 +185,7 @@ Image::load() {
void void
Image::loaded() { Image::loaded() {
HandleScope scope; HandleScope scope;
complete = true;
if (!onload.IsEmpty()) { if (!onload.IsEmpty()) {
TryCatch try_catch; TryCatch try_catch;
@ -182,7 +194,6 @@ Image::loaded() {
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
error(try_catch.Exception()); error(try_catch.Exception());
} }
complete = true;
} }
Unref(); Unref();

1
src/Image.h

@ -24,6 +24,7 @@ class Image: public node::ObjectWrap {
static Handle<Value> GetSrc(Local<String> prop, const AccessorInfo &info); static Handle<Value> GetSrc(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetOnload(Local<String> prop, const AccessorInfo &info); static Handle<Value> GetOnload(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetOnerror(Local<String> prop, const AccessorInfo &info); static Handle<Value> GetOnerror(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetComplete(Local<String> prop, const AccessorInfo &info);
static void SetSrc(Local<String> prop, Local<Value> val, const AccessorInfo &info); static void SetSrc(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetOnload(Local<String> prop, Local<Value> val, const AccessorInfo &info); static void SetOnload(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetOnerror(Local<String> prop, Local<Value> val, const AccessorInfo &info); static void SetOnerror(Local<String> prop, Local<Value> val, const AccessorInfo &info);

Loading…
Cancel
Save