comparison tools/gen_v8_binding.m4 @ 660:dde4e3cc9529

Enabling error handling on binding
author Thinker K.F. Li <thinker@branda.to>
date Sun, 01 Aug 2010 20:17:39 +0800
parents d4aa1cce0af7
children 974d98233eab
comparison
equal deleted inserted replaced
659:d4aa1cce0af7 660:dde4e3cc9529
149 char *arg_$][1; 149 char *arg_$][1;
150 ])dnl 150 ])dnl
151 define([FUNC], [dnl 151 define([FUNC], [dnl
152 Handle<Function> arg_$][1; 152 Handle<Function> arg_$][1;
153 ])dnl 153 ])dnl
154 define([SELF], [])dnl
155 define([ERR], [])dnl
154 ]) 156 ])
155 157
156 define([START_METHOD_ARG_TYPE_CHK], [dnl 158 define([START_METHOD_ARG_TYPE_CHK], [dnl
157 define([INT], [ || 159 define([INT], [ ||
158 !args[[i++]]->IsInt32()])dnl 160 !args[[i++]]->IsInt32()])dnl
162 !args[[i++]]->IsObject()])dnl 164 !args[[i++]]->IsObject()])dnl
163 define([STR], [ || 165 define([STR], [ ||
164 !args[[i++]]->IsString()])dnl 166 !args[[i++]]->IsString()])dnl
165 define([FUNC], [ || 167 define([FUNC], [ ||
166 !args[[i++]]->IsFunction()])dnl 168 !args[[i++]]->IsFunction()])dnl
169 define([SELF], [])dnl
170 define([ERR], [])dnl
171 ])
172
173 define([START_TYPE_CHK], [dnl
174 define([INT], [$1->IsInt32()])dnl
175 define([NUMBER], [$1->IsNumber()])dnl
176 define([OBJ], [$1->IsObject()])dnl
177 define([STR], [$1->IsString()])dnl
178 define([FUNC], [$1->IsFunction()])dnl
167 ]) 179 ])
168 180
169 define([START_METHOD_ARG_ASSIGN], [dnl 181 define([START_METHOD_ARG_ASSIGN], [dnl
170 define([INT], [dnl 182 define([INT], [dnl
171 arg_$][1 = args[[i++]]->Int32Value(); 183 arg_$][1 = args[[i++]]->Int32Value();
180 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString())); 192 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));
181 ])dnl 193 ])dnl
182 define([FUNC], [dnl 194 define([FUNC], [dnl
183 arg_$][1 = args[[i++]].As<Function>(); 195 arg_$][1 = args[[i++]].As<Function>();
184 ])dnl 196 ])dnl
197 define([SELF], [])dnl
198 define([ERR], [])dnl
185 ]) 199 ])
186 200
187 define([START_VALUE_ASSIGN], [dnl 201 define([START_VALUE_ASSIGN], [dnl
188 define([INT], [dnl 202 define([INT], [dnl
189 $1 = $2->Int32Value(); 203 $1 = $2->Int32Value();
206 define([INT], [arg_$][1])dnl 220 define([INT], [arg_$][1])dnl
207 define([NUMBER], [arg_$][1])dnl 221 define([NUMBER], [arg_$][1])dnl
208 define([OBJ], [arg_$][1])dnl 222 define([OBJ], [arg_$][1])dnl
209 define([STR], [arg_$][1])dnl 223 define([STR], [arg_$][1])dnl
210 define([FUNC], [arg_$][1])dnl 224 define([FUNC], [arg_$][1])dnl
225 define([SELF], [self])dnl
226 define([ERR], [&_err])dnl
211 ]) 227 ])
212 228
213 define([START_METHOD_RET_VAL], [dnl 229 define([START_METHOD_RET_VAL], [dnl
214 define([INT], [dnl 230 define([INT], [dnl
215 int _ret; 231 int _ret;
276 undefine([INT])dnl 292 undefine([INT])dnl
277 undefine([NUMBER])dnl 293 undefine([NUMBER])dnl
278 undefine([OBJ])dnl 294 undefine([OBJ])dnl
279 undefine([STR])dnl 295 undefine([STR])dnl
280 undefine([FUNC])dnl 296 undefine([FUNC])dnl
297 undefine([SELF])dnl
298 undefine([ERR])dnl
281 ]) 299 ])
282 300
283 define([START_METHOD], [dnl 301 define([START_METHOD], [dnl
284 define([METHOD], [ 302 define([METHOD], [
285 static Handle<Value> 303 static Handle<Value>
286 PROJ_PREFIX[]STRUCT_NAME[]_$][1(const Arguments &args) { 304 PROJ_PREFIX[]STRUCT_NAME[]_$][1(const Arguments &args) {
287 int i; 305 int i;
288 int argc = args.Length(); 306 int argc = args.Length();
289 Handle<Object> self = args.This(); 307 Handle<Object> self = args.This();
290 STRUCT_TYPE *_self = (STRUCT_TYPE *)UNWRAP(self); 308 STRUCT_TYPE *_self = (STRUCT_TYPE *)UNWRAP(self);
309 const char *_err = NULL;
291 foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl 310 foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl
292 START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG 311 START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG
293 312
294 if(argc != $][4) 313 if(argc != $][4)
295 THROW("Invalid number of arguments (!=$][4)"); 314 THROW("Invalid number of arguments (!=$][4)");
296 i = 0; 315 i = 0;
297 if(0]dnl 316 if(0[]dnl
298 foreach([ITER], $][3, [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG])[) 317 foreach([ITER], $][3, [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG]))
299 THROW("Invalid argument type"); 318 THROW("Invalid argument type");
300 319
301 i = 0; 320 i = 0;
302 foreach([ITER], $][3, [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])dnl 321 foreach([ITER], $][3, [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])dnl
303 322
304 START_METHOD_RET_ASSIGN[]$][5[]STOP_METHOD_ARG[]$][2(_self[]foreach([ITER], $][3, [START_METHOD_ARG_PASS[], ITER[]STOP_METHOD_ARG])); 323 START_METHOD_RET_ASSIGN[]$][5[]STOP_METHOD_ARG[]$][2(_self[]foreach([ITER], $][3, [START_METHOD_ARG_PASS[], ITER[]STOP_METHOD_ARG]));
324 if(_err)
325 THROW(_err);
305 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl 326 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl
306 ifelse($][5, [], [ 327 ifelse($][5, [], [
307 return Null(); 328 return Null();
308 ])dnl 329 ])dnl
309 } 330 }
324 define([DEF_GET_INDEX], [ 345 define([DEF_GET_INDEX], [
325 static Handle<Value> 346 static Handle<Value>
326 PROJ_PREFIX[]STRUCT_NAME[]_get_index(uint32_t index, const AccessorInfo &info) { 347 PROJ_PREFIX[]STRUCT_NAME[]_get_index(uint32_t index, const AccessorInfo &info) {
327 Handle<Object> self = info.This(); 348 Handle<Object> self = info.This();
328 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self); 349 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self);
350 const char *_err = NULL;
329 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl 351 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl
330 352
331 _ret = $1(obj, index); 353 _ret = $1(obj, self, index, &_err);
354 if(_err)
355 THROW(_err);
332 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl 356 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl
333 } 357 }
334 ]) 358 ])
335 359
336 define([DEF_SET_INDEX], [ 360 define([DEF_SET_INDEX], [
337 static Handle<Value> 361 static Handle<Value>
338 PROJ_PREFIX[]STRUCT_NAME[]_set_index(uint32_t index, Local<Value> value, 362 PROJ_PREFIX[]STRUCT_NAME[]_set_index(uint32_t index, Local<Value> value,
339 const AccessorInfo &info) { 363 const AccessorInfo &info) {
340 Handle<Object> self = info.This(); 364 Handle<Object> self = info.This();
341 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self); 365 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self);
366 const char *_err = NULL;
342 START_VAR([in_value])[]$2[]STOP_METHOD_ARG[]dnl 367 START_VAR([in_value])[]$2[]STOP_METHOD_ARG[]dnl
343 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl 368 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl
344 369
370 if(START_TYPE_CHK(value)[]![]$2[]STOP_METHOD_ARG)
371 THROW("Invalid value type");
372
345 START_VALUE_ASSIGN(in_value, value)[]$2[]STOP_METHOD_ARG[]dnl 373 START_VALUE_ASSIGN(in_value, value)[]$2[]STOP_METHOD_ARG[]dnl
346 _ret = $1(obj, index, in_value); 374 _ret = $1(obj, self, index, in_value, &_err);
375 if(_err) THROW(_err);
347 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl 376 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl
348 } 377 }
349 ]) 378 ])
350 379
351 define([INSTALL_INDEX_FUNCTIONS],[]) 380 define([INSTALL_INDEX_FUNCTIONS],[dnl
381 define([FIRST], [$][1])dnl
382 ifdef([GET_INDEX], [ifdef([SET_INDEX], [dnl
383 inst_temp->SetIndexedPropertyHandler(PROJ_PREFIX[]STRUCT_NAME[]_get_index,
384 PROJ_PREFIX[]STRUCT_NAME[]_set_index);
385 ], [dnl
386 inst_temp->SetIndexedPropertyHandler(PROJ_PREFIX[]STRUCT_NAME[]_get_index);
387 ])])dnl
388 undefine([FIRST])dnl
389 ])
352 390
353 dnl 391 dnl
354 dnl STRUCT(struct_name, struct_type, member_vars, methods) 392 dnl STRUCT(struct_name, struct_type, member_vars, methods)
355 dnl 393 dnl
356 define([STRUCT], [dnl 394 define([STRUCT], [dnl
397 func_temp->SetClassName(String::New("]STRUCT_NAME[")); 435 func_temp->SetClassName(String::New("]STRUCT_NAME["));
398 inst_temp = func_temp->InstanceTemplate(); 436 inst_temp = func_temp->InstanceTemplate();
399 inst_temp->SetInternalFieldCount(1); 437 inst_temp->SetInternalFieldCount(1);
400 ] 438 ]
401 foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl 439 foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl
402 inst_temp = func_temp->InstanceTemplate();
403 INSTALL_INDEX_FUNCTIONS[]dnl 440 INSTALL_INDEX_FUNCTIONS[]dnl
404 441
442 proto_temp = func_temp->PrototypeTemplate();
405 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl 443 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl
406 444
407 PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp); 445 PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp);
408 }]dnl 446 }]dnl
409 dnl 447 dnl
425 */ 463 */
426 static Handle<Value> 464 static Handle<Value>
427 PROJ_PREFIX[]$1(const Arguments &args) { 465 PROJ_PREFIX[]$1(const Arguments &args) {
428 int argc = args.Length(); 466 int argc = args.Length();
429 int i; 467 int i;
468 const char *_err = NULL;
430 foreach([ITER], ($3), [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl 469 foreach([ITER], ($3), [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl
431 START_METHOD_RET_VAL[]$5[]STOP_METHOD_ARG[]dnl 470 START_METHOD_RET_VAL[]$5[]STOP_METHOD_ARG[]dnl
432 471
433 if(argc != $4) 472 if(argc != $4)
434 THROW("Invalid number of arguments (!=$][4)"); 473 THROW("Invalid number of arguments (!=$][4)");
440 i = 0; 479 i = 0;
441 foreach([ITER], ($3), [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])dnl 480 foreach([ITER], ($3), [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])dnl
442 481
443 define([SEP], [])dnl 482 define([SEP], [])dnl
444 START_METHOD_RET_ASSIGN[]$5[]STOP_METHOD_ARG[]$2(foreach([ITER], ($3), [START_METHOD_ARG_PASS[]SEP[]ITER[]STOP_METHOD_ARG[]define([SEP], [, ])]));[]undefine([SEP]) 483 START_METHOD_RET_ASSIGN[]$5[]STOP_METHOD_ARG[]$2(foreach([ITER], ($3), [START_METHOD_ARG_PASS[]SEP[]ITER[]STOP_METHOD_ARG[]define([SEP], [, ])]));[]undefine([SEP])
484 if(_err)
485 THROW(_err);
445 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl 486 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl
446 ifelse($][5, [], [ 487 ifelse($][5, [], [
447 return Null(); 488 return Null();
448 ])dnl 489 ])dnl
449 } 490 }