Browse Source

Added js Image#inspect()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
38b0212560
  1. 27
      lib/Image.js
  2. 6
      lib/canvas.js
  3. 18
      src/Image.cc
  4. 1
      src/Image.h

27
lib/Image.js

@ -0,0 +1,27 @@
/*!
* Canvas - Image
* Copyright (c) 2010 LearnBoost <tj@learnboost.com>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var Canvas = require('../build/default/canvas')
, Image = Canvas.Image;
/**
* Inspect image.
*
* @return {String}
* @api public
*/
Image.prototype.inspect = function(){
return '[Image'
+ (this.complete ? ' complete' : '')
// + ' ' + this.src
+ ']';
};

6
lib/canvas.js

@ -49,6 +49,12 @@ exports.Image = Image;
require('./context2d');
/**
* Image implementation.
*/
require('./image');
/**
* Inspect canvas.
*

18
src/Image.cc

@ -20,7 +20,6 @@ Image::Initialize(Handle<Object> target) {
t->SetClassName(String::NewSymbol("Image"));
Local<ObjectTemplate> proto = t->PrototypeTemplate();
NODE_SET_PROTOTYPE_METHOD(t, "inspect", Inspect);
proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc);
proto->SetAccessor(String::NewSymbol("complete"), GetComplete);
proto->SetAccessor(String::NewSymbol("width"), GetWidth);
@ -42,23 +41,6 @@ Image::New(const Arguments &args) {
return args.This();
}
/*
* Custom inspect.
*/
Handle<Value>
Image::Inspect(const Arguments &args) {
HandleScope scope;
Image *img = ObjectWrap::Unwrap<Image>(args.This());
Local<String> str = String::New("[Image");
if (img->filename) {
str = String::Concat(str, String::New(" "));
str = String::Concat(str, String::New(img->filename));
}
str = String::Concat(str, String::New("]"));
return scope.Close(str);
}
/*
* Get complete boolean.
*/

1
src/Image.h

@ -21,7 +21,6 @@ class Image: public node::ObjectWrap {
Persistent<Function> onerror;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> Inspect(const Arguments &args);
static Handle<Value> GetSrc(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);

Loading…
Cancel
Save