annotate nodejs/coord.cc @ 560:ce7a35abcb0d Android_Skia

Function to instantiate coord for Javascript
author Thinker K.F. Li <thinker@branda.to>
date Mon, 07 Jun 2010 11:47:34 +0800
parents 0ca8437a91fa
children 1b6402f07cd4
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
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
11 #include "mbfly_njs.h"
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
12
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
13 #ifndef ASSERT
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
14 #define ASSERT(x)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
15 #endif
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
16
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 using namespace v8;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 static Handle<Value>
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 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
21 HandleScope scope;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 Handle<Object> self;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 coord_t *coord;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 co_aix v;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
26 if(index < 0 || index >= 6)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
27 THROW("Invalid index");
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 self = info.This();
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
30 coord = (coord_t *)UNWRAP(self);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 v = coord_get_matrix(coord)[index];
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 return Number::New(v);
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 }
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 static Handle<Value>
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 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
38 const AccessorInfo &info) {
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 HandleScope scope;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 Handle<Object> self;
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
42 Handle<Object> js_rt;
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 redraw_man_t *rdman;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 coord_t *coord;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 co_aix v;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
47 if(index < 0 || index >= 6)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
48 THROW("Invalid Index");
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
49 if(!value->IsNumber())
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
50 THROW("Invalid value");
557
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 self = info.This();
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
53 coord = (coord_t *)UNWRAP(self);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 v = value->NumberValue();
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 coord_get_matrix(coord)[index] = v;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
57 js_rt = GET(self, "mbrt")->ToObject();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
58 rdman = xnjsmb_rt_rdman(js_rt);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 rdman_coord_changed(rdman, coord);
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 return value;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 }
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
63
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
64 static Persistent<ObjectTemplate> coord_obj_temp;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
65
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
66 static void
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
67 xnjsmb_init_temp(void) {
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
68 coord_obj_temp = Persistent<ObjectTemplate>(ObjectTemplate::New());
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
69 coord_obj_temp->SetIndexedPropertyHandler(xnjsmb_coord_get_index,
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
70 xnjsmb_coord_set_index);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
71 coord_obj_temp->SetInternalFieldCount(1);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
72 }
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
73
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
74 /*! \brief Create a coord object associated with the rdman of the runtime.
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
75 *
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
76 * Two internal fields, coord and rdman.
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
77 */
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
78 Handle<Value>
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
79 xnjsmb_coord_new(const Arguments &args) {
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
80 HandleScope scope;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
81 Handle<Object> js_rt;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
82 Handle<Object> coord_obj, parent_obj;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
83 njs_runtime_t *rt;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
84 redraw_man_t *rdman;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
85 coord_t *coord, *parent = NULL;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
86 int argc;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
87 static int init_temp = 0;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
88
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
89 if(!init_temp) {
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
90 xnjsmb_init_temp();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
91 init_temp = 1;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
92 }
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
93
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
94 argc = args.Length();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
95 if(argc > 1)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
96 THROW("Too many arguments (> 1)");
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
97
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
98 js_rt = args.This();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
99 rt = (njs_runtime_t *)UNWRAP(js_rt);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
100 rdman = X_njs_MB_rdman(rt);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
101
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
102 if(argc == 1) {
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
103 parent_obj = args[0]->ToObject();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
104 parent = (coord_t *)UNWRAP(parent_obj);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
105 }
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
106
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
107 /*
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
108 * Set Javascript object
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
109 */
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
110 coord = rdman_coord_new(rdman, parent);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
111 ASSERT(coord != NULL);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
112
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
113 coord_obj = coord_obj_temp->NewInstance();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
114 ASSERT(coord_obj != NULL);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
115 WRAP(coord_obj, coord);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
116
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
117 if(parent != NULL)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
118 SET(coord_obj, "parent", parent_obj);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
119 SET(coord_obj, "mbrt", js_rt);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
120
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
121 return coord_obj;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
122 }