Mercurial > MadButterfly
annotate nodejs/coord.cc @ 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 | |
children | ce7a35abcb0d |
rev | line source |
---|---|
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <stdio.h> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include <v8.h> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 extern "C" { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 #include "mb.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 #include "mb_X_supp.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 #include "mb_tools.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 #include "X_supp_njs.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 using namespace v8; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 static Handle<Value> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 xnjsmb_coord_get_index(uint32_t index, const AccessorInfo &info) { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 HandleScope scope; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 Handle<Object> self; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 coord_t *coord; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 co_aix v; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 Handle<Value> exc; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 if(index < 0 || index >= 6) { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 exc = Exception::Error(String::New("Invalid index")); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 return ThrowException(exc); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 self = info.This(); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 coord = (coord_t *)External::Unwrap(self->Get(String::New("_njs_coord"))); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 v = coord_get_matrix(coord)[index]; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 return Number::New(v); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 static Handle<Value> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 xnjsmb_coord_set_index(uint32_t index, Local<Value> value, |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 const AccessorInfo &info) { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 HandleScope scope; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 Handle<Object> self; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 redraw_man_t *rdman; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 coord_t *coord; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 co_aix v; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 Handle<Value> exc; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 if(index < 0 || index >= 6) { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 exc = Exception::Error(String::New("Invalid index")); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 return ThrowException(exc); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 if(!value->IsNumber()) { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 exc = Exception::Error(String::New("Invalid value")); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 return ThrowException(exc); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 self = info.This(); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 coord = (coord_t *)External::Unwrap(self->Get(String::New("_njs_coord"))); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 v = value->NumberValue(); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 coord_get_matrix(coord)[index] = v; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 rdman = (redraw_man_t *) |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 External::Unwrap(self->Get(String::New("_njs_rdman"))); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 rdman_coord_changed(rdman, coord); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 return value; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 } |