# HG changeset patch # User Thinker K.F. Li # Date 1280277075 -28800 # Node ID a65720721c60dab8f915a76bbca02e080f1e04ae # Parent 4f7b4ff31c0cbc6d52ad4f2c632f7f89fafab21d Fix issue of exception of internal field. img_ldr is a function to return a new img_ldr, not a constructor as in previous implementation. This changeset fix semantic error on xnjsmb_img_ldr_new(). diff -r 4f7b4ff31c0c -r a65720721c60 nodejs/image_ldr.cc --- a/nodejs/image_ldr.cc Tue Jul 27 22:02:40 2010 +0800 +++ b/nodejs/image_ldr.cc Wed Jul 28 08:31:15 2010 +0800 @@ -59,7 +59,7 @@ /*! \brief Constructor function of img_ldr Javascript objects. */ static Handle -xnjsmb_img_ldr_new(const Arguments &args) { +xnjsmb_img_ldr(const Arguments &args) { HandleScope scope; int argc = args.Length(); Handle self = args.This(); @@ -82,6 +82,29 @@ return Null(); } +static Persistent xnjsmb_img_ldr_temp; + +static Handle +xnjsmb_img_ldr_new(const Arguments &args) { + HandleScope scope; + int argc = args.Length(); + Handle il_args[1]; + Handle img_ldr; + Handle func; + + if(argc != 1) + THROW("Invalid number of arguments (!= 1)"); + if(!args[0]->IsString()) + THROW("Invalid argument type"); + + il_args[0] = args[0]; + func = xnjsmb_img_ldr_temp->GetFunction(); + img_ldr = func->NewInstance(1, il_args); + + scope.Close(img_ldr); + return img_ldr; +} + /* @} */ /*! \brief Initialize image loader. @@ -92,6 +115,7 @@ void xnjsmb_img_ldr_init_mb_rt_temp(Handle rt_temp) { HandleScope scope; + Handle img_ldr_temp; Handle img_ldr_new_temp; Handle ldr_inst_temp; Handle ldr_proto_temp; @@ -104,15 +128,19 @@ img_data_temp = Persistent::New(_img_data_temp); /* Setup img_ldr class */ - img_ldr_new_temp = FunctionTemplate::New(xnjsmb_img_ldr_new); - img_ldr_new_temp->SetClassName(String::New("img_ldr")); - ldr_inst_temp = img_ldr_new_temp->InstanceTemplate(); + img_ldr_temp = FunctionTemplate::New(xnjsmb_img_ldr); + img_ldr_temp->SetClassName(String::New("img_ldr")); + ldr_inst_temp = img_ldr_temp->InstanceTemplate(); ldr_inst_temp->SetInternalFieldCount(1); /* Set method load() for img_ldr */ - ldr_proto_temp = img_ldr_new_temp->PrototypeTemplate(); + ldr_proto_temp = img_ldr_temp->PrototypeTemplate(); img_ldr_load_temp = FunctionTemplate::New(xnjsmb_img_ldr_load); SET(ldr_proto_temp, "load", img_ldr_load_temp); - + + xnjsmb_img_ldr_temp = Persistent::New(img_ldr_temp); + + /* Initialize img_ldr_new function */ + img_ldr_new_temp = FunctionTemplate::New(xnjsmb_img_ldr_new); SET(rt_temp, "img_ldr_new", img_ldr_new_temp->GetFunction()); } diff -r 4f7b4ff31c0c -r a65720721c60 nodejs/sample.png Binary file nodejs/sample.png has changed diff -r 4f7b4ff31c0c -r a65720721c60 nodejs/shapes.cc --- a/nodejs/shapes.cc Tue Jul 27 22:02:40 2010 +0800 +++ b/nodejs/shapes.cc Wed Jul 28 08:31:15 2010 +0800 @@ -435,6 +435,7 @@ xnjsmb_init_shape_temp(); xnjsmb_init_path_temp(); xnjsmb_init_stext_temp(); + xnjsmb_init_image_temp(); temp_init_flag = 1; } diff -r 4f7b4ff31c0c -r a65720721c60 nodejs/testcase.js --- a/nodejs/testcase.js Tue Jul 27 22:02:40 2010 +0800 +++ b/nodejs/testcase.js Wed Jul 28 08:31:15 2010 +0800 @@ -11,6 +11,14 @@ sys.puts("coord matrix: " + [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]); +/* Testcase for image shapes */ +var img = mb_rt.image_new(10, 10, 50, 50); +var ldr = mbfly.img_ldr_new("."); +var img_data = ldr.load("sample.png"); +var paint = mb_rt.paint_image_new(img_data); +paint.fill(img); +root.add_shape(img); + sys.puts(mb_rt.path_new); var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z"); sys.puts(path);