changeset 557:0ca8437a91fa Android_Skia

Implement Indexed Property interceptors
author Thinker K.F. Li <thinker@branda.to>
date Sun, 06 Jun 2010 21:27:34 +0800
parents c9d23f7279a4
children d61133da2845
files nodejs/Makefile.am nodejs/coord.cc nodejs/mbfly_njs.cc nodejs/wscript
diffstat 4 files changed, 67 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/Makefile.am	Sun Jun 06 19:13:21 2010 +0800
+++ b/nodejs/Makefile.am	Sun Jun 06 21:27:34 2010 +0800
@@ -1,5 +1,5 @@
 
-mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c
+mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc
 mbfly_node_CFLAGS= -I$(abs_top_builddir)/include \
 	-I$(abs_top_srcdir)/include \
 	-I$(prefix)/include \
@@ -12,6 +12,7 @@
 mbfly.node: wscript $(mbfly_node_SRCS)
 	cd $(srcdir); \
 	CFLAGS="$(mbfly_node_CFLAGS)" \
+		CXXFLAGS="$(mbfly_node_CFLAGS)" \
 		LDFLAGS="$(mbfly_node_LDFLAGS)" \
 		TOP_BUILDDIR="$(abs_top_builddir)" \
 		WAFLOCK=$(abs_builddir)/.lock-wscript \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/coord.cc	Sun Jun 06 21:27:34 2010 +0800
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <v8.h>
+
+extern "C" {
+#include "mb.h"
+#include "mb_X_supp.h"
+#include "mb_tools.h"
+#include "X_supp_njs.h"
+}
+
+using namespace v8;
+
+static Handle<Value>
+xnjsmb_coord_get_index(uint32_t index, const AccessorInfo &info) {
+    HandleScope scope;
+    Handle<Object> self;
+    coord_t *coord;
+    co_aix v;
+    Handle<Value> exc;
+
+    if(index < 0 || index >= 6) {
+	exc = Exception::Error(String::New("Invalid index"));
+	return ThrowException(exc);
+    }
+    
+    self = info.This();
+    coord = (coord_t *)External::Unwrap(self->Get(String::New("_njs_coord")));
+    v = coord_get_matrix(coord)[index];
+
+    return Number::New(v);
+}
+
+static Handle<Value>
+xnjsmb_coord_set_index(uint32_t index, Local<Value> value,
+		       const AccessorInfo &info) {
+    
+    HandleScope scope;
+    Handle<Object> self;
+    redraw_man_t *rdman;
+    coord_t *coord;
+    co_aix v;
+    Handle<Value> exc;
+
+    if(index < 0 || index >= 6) {
+	exc = Exception::Error(String::New("Invalid index"));
+	return ThrowException(exc);
+    }
+    if(!value->IsNumber()) {
+	exc = Exception::Error(String::New("Invalid value"));
+	return ThrowException(exc);
+    }
+
+    self = info.This();
+    coord = (coord_t *)External::Unwrap(self->Get(String::New("_njs_coord")));
+    v = value->NumberValue();
+    coord_get_matrix(coord)[index] = v;
+
+    rdman = (redraw_man_t *)
+	External::Unwrap(self->Get(String::New("_njs_rdman")));
+    rdman_coord_changed(rdman, coord);
+
+    return value;
+}
--- a/nodejs/mbfly_njs.cc	Sun Jun 06 19:13:21 2010 +0800
+++ b/nodejs/mbfly_njs.cc	Sun Jun 06 21:27:34 2010 +0800
@@ -21,6 +21,7 @@
  */
 static Handle<Value>
 xnjsmb_new(const Arguments &args) {
+    HandleScope scope;
     int argc;
     Handle<Value> exc;
     njs_runtime_t *rt;
--- a/nodejs/wscript	Sun Jun 06 19:13:21 2010 +0800
+++ b/nodejs/wscript	Sun Jun 06 21:27:34 2010 +0800
@@ -23,7 +23,7 @@
     
     obj = conf.new_task_gen('cxx', 'shlib', 'node_addon')
     obj.target = 'mbfly'
-    obj.source = 'mbfly_njs.cc'
+    obj.source = 'mbfly_njs.cc coord.cc'
     obj.add_objects = 'X_supp_njs.o'
     obj.staticlib = 'mbfly'