Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Use C99 bool for simple conditionals, and JSBool only for JS engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewd committed Apr 21, 2008
1 parent dc42336 commit 0746d92
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions ext/spidermonkey/conversions.c
Expand Up @@ -100,12 +100,12 @@ static VALUE convert_regexp_to_ruby(OurContext* context, jsval regexp)
INT2NUM(re->flags));
}

static JSBool js_value_is_regexp(OurContext* context, jsval maybe_regexp)
static bool js_value_is_regexp(OurContext* context, jsval maybe_regexp)
{
return JS_InstanceOf(context->js, JSVAL_TO_OBJECT(maybe_regexp), &js_RegExpClass, NULL);
}

static JSBool js_value_is_symbol(OurContext* context, jsval maybe_symbol)
static bool js_value_is_symbol(OurContext* context, jsval maybe_symbol)
{
jsval nsJohnson, cSymbol;

Expand All @@ -118,7 +118,7 @@ static JSBool js_value_is_symbol(OurContext* context, jsval maybe_symbol)
JSBool is_a_symbol;
assert(JS_HasInstance(context->js, JSVAL_TO_OBJECT(cSymbol), maybe_symbol, &is_a_symbol));

return is_a_symbol;
return is_a_symbol != JS_FALSE;
}

VALUE convert_to_ruby(OurContext* context, jsval js)
Expand Down
43 changes: 21 additions & 22 deletions ext/spidermonkey/js_land_proxy.c
Expand Up @@ -51,33 +51,33 @@ static JSClass JSLandCallableProxyClass = {
call
};

static JSBool autovivified_p(VALUE ruby_context, VALUE self, char* name)
static bool autovivified_p(VALUE ruby_context, VALUE self, char* name)
{
return rb_funcall(Johnson_SpiderMonkey_JSLandProxy(), rb_intern("autovivified?"), 2,
self, rb_str_new2(name));
return RTEST(rb_funcall(Johnson_SpiderMonkey_JSLandProxy(), rb_intern("autovivified?"), 2,
self, rb_str_new2(name)));
}

static JSBool const_p(VALUE self, char* name)
static bool const_p(VALUE self, char* name)
{
return rb_obj_is_kind_of(self, rb_cModule)
&& rb_is_const_id(rb_intern(name))
&& rb_funcall(self, rb_intern("const_defined?"), 1, ID2SYM(rb_intern(name)));
&& RTEST( rb_funcall(self, rb_intern("const_defined?"), 1, ID2SYM(rb_intern(name))) );
}

static JSBool global_p(char* name)
static bool global_p(char* name)
{
return rb_ary_includes(rb_f_global_variables(), rb_str_new2(name));
}

static JSBool method_p(VALUE self, char* name)
static bool method_p(VALUE self, char* name)
{
return rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern(name)));
return RTEST( rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern(name))) );
}

static JSBool attribute_p(VALUE self, char* name)
static bool attribute_p(VALUE self, char* name)
{
if (!method_p(self, name))
return JS_FALSE;
return false;

VALUE rb_id = rb_intern(name);
VALUE rb_method = rb_funcall(self, rb_intern("method"), 1, ID2SYM(rb_id));
Expand All @@ -86,24 +86,23 @@ static JSBool attribute_p(VALUE self, char* name)
Data_Get_Struct(rb_method, METHOD, method);

return nd_type(method->body) == NODE_IVAR
|| rb_funcall(Johnson_SpiderMonkey_JSLandProxy(),
rb_intern("js_property?"), 2, self, ID2SYM(rb_id));
|| RTEST(rb_funcall(Johnson_SpiderMonkey_JSLandProxy(),
rb_intern("js_property?"), 2, self, ID2SYM(rb_id)));
}

static JSBool indexable_p(VALUE self)
static bool indexable_p(VALUE self)
{
VALUE v = rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]")));
return RTEST(v) ? JS_TRUE : JS_FALSE;
return RTEST(rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]"))));
}

static JSBool has_key_p(VALUE self, char* name)
static bool has_key_p(VALUE self, char* name)
{
return rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]")))
&& rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("key?")))
&& rb_funcall(self, rb_intern("key?"), 1, rb_str_new2(name));
return RTEST(rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]"))))
&& RTEST(rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("key?"))))
&& RTEST(rb_funcall(self, rb_intern("key?"), 1, rb_str_new2(name)));
}

static JSBool respond_to_p(JSContext* js_context, JSObject* obj, char* name)
static bool respond_to_p(JSContext* js_context, JSObject* obj, char* name)
{
VALUE ruby_context;
assert(ruby_context = (VALUE)JS_GetContextPrivate(js_context));
Expand Down Expand Up @@ -385,7 +384,7 @@ static JSBool call(JSContext* js_context, JSObject* obj, uintN argc, jsval* argv
3, self, ID2SYM(rb_intern("call")), args), retval);
}

JSBool js_value_is_proxy(OurContext* context, jsval maybe_proxy)
bool js_value_is_proxy(OurContext* context, jsval maybe_proxy)
{
JSClass* klass = JS_GET_CLASS(context->js, JSVAL_TO_OBJECT(maybe_proxy));

Expand Down Expand Up @@ -446,7 +445,7 @@ JSBool make_js_land_proxy(OurContext* context, VALUE value, jsval* retval)
rb_funcall(Johnson_SpiderMonkey_JSLandProxy(),
rb_intern("treat_all_properties_as_methods"), 1, value);

JSBool callable_p = rb_class_of(value) == rb_cMethod
bool callable_p = rb_class_of(value) == rb_cMethod
|| rb_class_of(value) == rb_cProc;

if (callable_p)
Expand Down
2 changes: 1 addition & 1 deletion ext/spidermonkey/js_land_proxy.h
Expand Up @@ -6,7 +6,7 @@

#define JS_FUNCTION_PROXY_PROPERTY "__isProxyForRubyProc"

JSBool js_value_is_proxy(OurContext* context, jsval maybe_proxy);
bool js_value_is_proxy(OurContext* context, jsval maybe_proxy);
VALUE unwrap_js_land_proxy(OurContext* context, jsval proxy);
JSBool make_js_land_proxy(OurContext* context, VALUE value, jsval* retval);

Expand Down
2 changes: 1 addition & 1 deletion ext/spidermonkey/ruby_land_proxy.c
Expand Up @@ -267,7 +267,7 @@ static void finalize(RubyLandProxy* proxy)
free(proxy);
}

JSBool ruby_value_is_proxy(VALUE maybe_proxy)
bool ruby_value_is_proxy(VALUE maybe_proxy)
{
return proxy_class == CLASS_OF(maybe_proxy);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/spidermonkey/ruby_land_proxy.h
Expand Up @@ -9,7 +9,7 @@ typedef struct {
OurContext* context;
} RubyLandProxy;

JSBool ruby_value_is_proxy(VALUE maybe_proxy);
bool ruby_value_is_proxy(VALUE maybe_proxy);
JSBool unwrap_ruby_land_proxy(OurContext* context, VALUE proxy, jsval* retval);
VALUE make_ruby_land_proxy(OurContext* context, jsval value);
void init_Johnson_SpiderMonkey_Proxy(VALUE spidermonkey);
Expand Down
1 change: 1 addition & 0 deletions ext/spidermonkey/spidermonkey.h
Expand Up @@ -3,6 +3,7 @@

#include <assert.h>
#include <stdio.h>
#include <stdbool.h>

#include <ruby.h>
#include "jsapi.h"
Expand Down

0 comments on commit 0746d92

Please sign in to comment.