comparison tools/gen_v8_binding.m4 @ 740:00a8c8a9e157

Check if an object valid in gen_v8_binding.m4
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 25 Aug 2010 10:07:33 +0800
parents 4a38e571cfce
children e21ccbc4afb1
comparison
equal deleted inserted replaced
739:4916c3a3fe3c 740:00a8c8a9e157
39 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 39 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
40 Handle<Object> self = info.This(); 40 Handle<Object> self = info.This();
41 STRUCT_TYPE *data; 41 STRUCT_TYPE *data;
42 42
43 data = (STRUCT_TYPE *)UNWRAP(self); 43 data = (STRUCT_TYPE *)UNWRAP(self);
44 if(data == NULL)
45 THROW("Invalid object");
44 return Integer::New(data->$][1); 46 return Integer::New(data->$][1);
45 } 47 }
46 48
47 static void 49 static void
48 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property, 50 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
50 const AccessorInfo &info) { 52 const AccessorInfo &info) {
51 Handle<Object> self = info.This(); 53 Handle<Object> self = info.This();
52 STRUCT_TYPE *data; 54 STRUCT_TYPE *data;
53 55
54 data = (STRUCT_TYPE *)UNWRAP(self); 56 data = (STRUCT_TYPE *)UNWRAP(self);
57 if(data == NULL)
58 THROW_noret("Invalid object");
55 data->$][1 = value->Int32Value(); 59 data->$][1 = value->Int32Value();
56 } 60 }
57 ]) 61 ])
58 fdefine([NUMBER], [ 62 fdefine([NUMBER], [
59 static Handle<Value> 63 static Handle<Value>
60 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 64 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
61 Handle<Object> self = info.This(); 65 Handle<Object> self = info.This();
62 STRUCT_TYPE *data; 66 STRUCT_TYPE *data;
63 67
64 data = (STRUCT_TYPE *)UNWRAP(self); 68 data = (STRUCT_TYPE *)UNWRAP(self);
69 if(data == NULL)
70 THROW("Invalid object");
65 return Number::New(data->$][1); 71 return Number::New(data->$][1);
66 } 72 }
67 73
68 static void 74 static void
69 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property, 75 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
71 const AccessorInfo &info) { 77 const AccessorInfo &info) {
72 Handle<Object> self = info.This(); 78 Handle<Object> self = info.This();
73 STRUCT_TYPE *data; 79 STRUCT_TYPE *data;
74 80
75 data = (STRUCT_TYPE *)UNWRAP(self); 81 data = (STRUCT_TYPE *)UNWRAP(self);
82 if(data == NULL)
83 THROW_noret("Invalid object");
76 data->$][1 = value->NumberValue(); 84 data->$][1 = value->NumberValue();
77 } 85 }
78 ]) 86 ])
79 fdefine([OBJ], [ 87 fdefine([OBJ], [
80 static Handle<Value> 88 static Handle<Value>
81 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 89 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
82 Handle<Object> self = info.This(); 90 Handle<Object> self = info.This();
83 STRUCT_TYPE *data; 91 STRUCT_TYPE *data;
84 92
85 data = (STRUCT_TYPE *)UNWRAP(self); 93 data = (STRUCT_TYPE *)UNWRAP(self);
94 if(data == NULL)
95 THROW("Invalid object");
86 return ]PROJ_PREFIX[$][2_new(($][3 *)data->$][1); 96 return ]PROJ_PREFIX[$][2_new(($][3 *)data->$][1);
87 } 97 }
88 98
89 static void 99 static void
90 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property, 100 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
94 Handle<Object> obj; 104 Handle<Object> obj;
95 $][3 *v; 105 $][3 *v;
96 STRUCT_TYPE *data; 106 STRUCT_TYPE *data;
97 107
98 data = (STRUCT_TYPE *)UNWRAP(self); 108 data = (STRUCT_TYPE *)UNWRAP(self);
109 if(data == NULL)
110 THROW_noret("Invalid object");
99 obj = value->ToObject(); 111 obj = value->ToObject();
100 v = ($][3 *)UNWRAP(obj); 112 v = ($][3 *)UNWRAP(obj);
113 if(v == NULL)
114 THROW_noret("Invalid object");
101 data->$][1 = v; 115 data->$][1 = v;
102 } 116 }
103 ]) 117 ])
104 fdefine([ARRAY], [ 118 fdefine([ARRAY], [
105 static Handle<Value> 119 static Handle<Value>
106 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 120 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
107 Handle<Object> self = info.This(); 121 Handle<Object> self = info.This();
108 STRUCT_TYPE *data; 122 STRUCT_TYPE *data;
109 123
110 data = (STRUCT_TYPE *)UNWRAP(self); 124 data = (STRUCT_TYPE *)UNWRAP(self);
125 if(data == NULL)
126 THROW("Invalid object");
111 return data->$][1; 127 return data->$][1;
112 } 128 }
113 129
114 static void 130 static void
115 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property, 131 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
118 Handle<Object> self = info.This(); 134 Handle<Object> self = info.This();
119 Handle<Object> obj; 135 Handle<Object> obj;
120 STRUCT_TYPE *data; 136 STRUCT_TYPE *data;
121 137
122 data = (STRUCT_TYPE *)UNWRAP(self); 138 data = (STRUCT_TYPE *)UNWRAP(self);
139 if(data == NULL)
140 THROW_noret("Invalid object");
123 data->$][1 = value; 141 data->$][1 = value;
124 } 142 }
125 ]) 143 ])
126 fdefine([STR], [ 144 fdefine([STR], [
127 static Handle<Value> 145 static Handle<Value>
128 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 146 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
129 Handle<Object> self = info.This(); 147 Handle<Object> self = info.This();
130 STRUCT_TYPE *data; 148 STRUCT_TYPE *data;
131 149
132 data = (STRUCT_TYPE *)UNWRAP(self); 150 data = (STRUCT_TYPE *)UNWRAP(self);
151 if(data == NULL)
152 THROW("Invalid object");
133 return String::New(data->$][1); 153 return String::New(data->$][1);
134 } 154 }
135 155
136 static void 156 static void
137 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property, 157 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
139 const AccessorInfo &info) { 159 const AccessorInfo &info) {
140 Handle<Object> self = info.This(); 160 Handle<Object> self = info.This();
141 STRUCT_TYPE *data; 161 STRUCT_TYPE *data;
142 162
143 data = (STRUCT_TYPE *)UNWRAP(self); 163 data = (STRUCT_TYPE *)UNWRAP(self);
164 if(data == NULL)
165 THROW_noret("Invalid object");
144 String::Utf8Value utf8(value->ToString()); 166 String::Utf8Value utf8(value->ToString());
145 free(data->$][1); 167 free(data->$][1);
146 data->$][1 = strdup(*utf8); 168 data->$][1 = strdup(*utf8);
147 } 169 }
148 ]) 170 ])
156 Handle<Value> _ret; 178 Handle<Value> _ret;
157 STRUCT_TYPE *data; 179 STRUCT_TYPE *data;
158 const char *err = NULL; 180 const char *err = NULL;
159 181
160 data = (STRUCT_TYPE *)UNWRAP(self); 182 data = (STRUCT_TYPE *)UNWRAP(self);
183 if(data == NULL)
184 THROW("Invalid object");
161 _ret = $][2(self, data, &err); 185 _ret = $][2(self, data, &err);
162 if(err) 186 if(err)
163 THROW(err); 187 THROW(err);
164 return _ret; 188 return _ret;
165 } 189 }
171 Handle<Object> self = info.This(); 195 Handle<Object> self = info.This();
172 STRUCT_TYPE *data; 196 STRUCT_TYPE *data;
173 const char *err = NULL; 197 const char *err = NULL;
174 198
175 data = (STRUCT_TYPE *)UNWRAP(self); 199 data = (STRUCT_TYPE *)UNWRAP(self);
200 if(data == NULL)
201 THROW_noret("Invalid object");
176 $][3(self, data, value, &err); 202 $][3(self, data, value, &err);
177 if(err) 203 if(err)
178 THROW_noret(err); 204 THROW_noret(err);
179 } 205 }
180 ]) 206 ])
261 fdefine([NUMBER], [dnl 287 fdefine([NUMBER], [dnl
262 arg_$][1 = args[[i++]]->NumberValue(); 288 arg_$][1 = args[[i++]]->NumberValue();
263 ])dnl 289 ])dnl
264 fdefine([OBJ], [dnl 290 fdefine([OBJ], [dnl
265 arg_$][1 = ($][3 *)UNWRAP(args[[i++]]->ToObject()); 291 arg_$][1 = ($][3 *)UNWRAP(args[[i++]]->ToObject());
292 if(arg_$][1 == NULL)
293 THROW("Invalid argument");
266 ])dnl 294 ])dnl
267 fdefine([ARRAY], [dnl 295 fdefine([ARRAY], [dnl
268 arg_$][1 = args[[i++]]; 296 arg_$][1 = args[[i++]];
269 ])dnl 297 ])dnl
270 fdefine([STR], [dnl 298 fdefine([STR], [dnl
285 fdefine([NUMBER], [dnl 313 fdefine([NUMBER], [dnl
286 $1 = $2->NumberValue(); 314 $1 = $2->NumberValue();
287 ])dnl 315 ])dnl
288 fdefine([OBJ], [dnl 316 fdefine([OBJ], [dnl
289 $1 = ($][2 *)UNWRAP($2->ToObject()); 317 $1 = ($][2 *)UNWRAP($2->ToObject());
318 if($1 == NULL)
319 THROW("Invalid argument");
290 ])dnl 320 ])dnl
291 fdefine([ARRAY], [dnl 321 fdefine([ARRAY], [dnl
292 $1 = $2; 322 $1 = $2;
293 ])dnl 323 ])dnl
294 fdefine([STR], [dnl 324 fdefine([STR], [dnl
420 const char *_err = NULL; 450 const char *_err = NULL;
421 foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl 451 foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl
422 START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG 452 START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG
423 Handle<Value> _ret_val; 453 Handle<Value> _ret_val;
424 454
455 if(_self == NULL)
456 THROW("Invalid object");
425 if(argc != $][4) 457 if(argc != $][4)
426 THROW("Invalid number of arguments (!=$][4)"); 458 THROW("Invalid number of arguments (!=$][4)");
427 i = 0; 459 i = 0;
428 if(0[]dnl 460 if(0[]dnl
429 foreach([ITER], $][3, [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG])) 461 foreach([ITER], $][3, [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG]))
471 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self); 503 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self);
472 const char *_err = NULL; 504 const char *_err = NULL;
473 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl 505 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl
474 Handle<Value> _ret_val; 506 Handle<Value> _ret_val;
475 507
508 if(obj == NULL)
509 THROW("Invalid object");
476 _ret = $1(obj, self, index, &_err); 510 _ret = $1(obj, self, index, &_err);
477 if(_err) 511 if(_err)
478 THROW(_err); 512 THROW(_err);
479 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl 513 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl
480 return _ret_val; 514 return _ret_val;
490 const char *_err = NULL; 524 const char *_err = NULL;
491 START_VAR([in_value])[]$2[]STOP_METHOD_ARG[]dnl 525 START_VAR([in_value])[]$2[]STOP_METHOD_ARG[]dnl
492 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl 526 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl
493 Handle<Value> _ret_val; 527 Handle<Value> _ret_val;
494 528
529 if(obj == NULL)
530 THROW("Invalid object");
495 if(START_TYPE_CHK(value)[]![]$2[]STOP_METHOD_ARG) 531 if(START_TYPE_CHK(value)[]![]$2[]STOP_METHOD_ARG)
496 THROW("Invalid value type"); 532 THROW("Invalid value type");
497 533
498 START_VALUE_ASSIGN(in_value, value)[]$2[]STOP_METHOD_ARG[]dnl 534 START_VALUE_ASSIGN(in_value, value)[]$2[]STOP_METHOD_ARG[]dnl
499 _ret = $1(obj, self, index, in_value, &_err); 535 _ret = $1(obj, self, index, in_value, &_err);