1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/v8_standalone.cpp
Bill Robertson 5f1ce0f692 ditto
2009-11-13 23:29:42 -05:00

58 lines
1.6 KiB
C++

#include "v8_standalone.h"
VALUE ruby_call_symbol;
VALUE ruby_respond_to_ID;
bool is_callable(VALUE& object) {
return Qtrue == rb_funcall(object, ruby_respond_to_ID, 1, ruby_call_symbol);
}
/**
* Debugging aid
*/
VALUE v8_what_is_this(VALUE self, VALUE object) {
VALUE boolean;
switch (TYPE(object)) {
case T_NIL:
printf("nil\n");
break;
case T_OBJECT:
printf("ordinary object\n");
if (is_callable(object)) {
printf("responds to call!<br/>");
}
break;
case T_CLASS:
printf("class[%s]<br/>", rb_class2name(object));
break;
case T_MODULE: printf("module\n"); break;
case T_FLOAT: printf("floating point number\n"); break;
case T_STRING: printf("string\n"); break;
case T_REGEXP: printf("regular expression\n"); break;
case T_ARRAY: printf("array\n"); break;
case T_FIXNUM: printf("Fixnum(31bit integer)\n"); break;
case T_HASH: printf("associative array\n"); break;
case T_STRUCT: printf("(Ruby) structure\n"); break;
case T_BIGNUM: printf("multi precision integer\n"); break;
case T_FILE: printf("IO\n"); break;
case T_TRUE: printf("true\n"); break;
case T_FALSE: printf("false\n"); break;
case T_DATA:
printf("data... inspecting\n");
if (is_callable(object)) {
printf("Responds to call!<br/>");
} else {
printf("Does *NOT* respond to call<br/>");
}
v8_what_is_this(Qnil, RDATA(object)->basic.klass);
break;
case T_SYMBOL: printf("symbol\n"); break;
default:
printf("I have no idea!!!\n");
rb_raise(rb_eTypeError, "not valid value");
break;
}
return Qnil;
}