1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

add mode comments, fix indentation

This commit is contained in:
Charles Lowell 2015-06-29 22:43:30 -05:00
parent 902a6f25c3
commit e452e123fd
2 changed files with 36 additions and 34 deletions

View file

@ -1,3 +1,4 @@
// -*- mode: c++ -*-
#ifndef RR_CLASS_BUILDER #ifndef RR_CLASS_BUILDER
#define RR_CLASS_BUILDER #define RR_CLASS_BUILDER

View file

@ -1,33 +1,34 @@
// -*- mode: c++ -*-
#ifndef RR_REF #ifndef RR_REF
#define RR_REF #define RR_REF
namespace rr { namespace rr {
/** /**
* A Reference to a V8 managed object * A Reference to a V8 managed object
* *
* Uses type coercion to quickly convert from a v8 handle * Uses type coercion to quickly convert from a v8 handle
* to a ruby object and back again. Suppose we have a v8 handle * to a ruby object and back again. Suppose we have a v8 handle
* that we want to return to Ruby. We can put it into a Ref: * that we want to return to Ruby. We can put it into a Ref:
* *
* v8::Handle<v8::Object> object = v8::Object::New(); * v8::Handle<v8::Object> object = v8::Object::New();
* VALUE val = Ref<v8::Object>(object); * VALUE val = Ref<v8::Object>(object);
* *
* this will create a `v8::Persistent` handle for the object * this will create a `v8::Persistent` handle for the object
* so that it will not be garbage collected by v8. It then * so that it will not be garbage collected by v8. It then
* stuffs this new persistent handle into a Data_Wrap_Struct * stuffs this new persistent handle into a Data_Wrap_Struct
* which can then be passed to Ruby code. When this struct * which can then be passed to Ruby code. When this struct
* is garbage collected by Ruby, it enqueues the corresponding * is garbage collected by Ruby, it enqueues the corresponding
* v8 handle to be released during v8 gc. * v8 handle to be released during v8 gc.
* *
* By the same token, you can use Refs to unwrap a Data_Wrap_Struct * By the same token, you can use Refs to unwrap a Data_Wrap_Struct
* which has been generated in this fashion and call through to * which has been generated in this fashion and call through to
* the underlying v8 methods. Suppose we are passed a VALUE `val` * the underlying v8 methods. Suppose we are passed a VALUE `val`
* wrapping a v8::Object: * wrapping a v8::Object:
* *
* Ref<v8::Object> object(val); * Ref<v8::Object> object(val);
* object->Get(v8::String::New("foo")); * object->Get(v8::String::New("foo"));
* *
*/ */
template <class T> template <class T>
class Ref { class Ref {
public: public:
@ -52,8 +53,8 @@ namespace rr {
virtual ~Ref() {} virtual ~Ref() {}
/* /*
* Coerce a Ref into a Ruby VALUE * Coerce a Ref into a Ruby VALUE
*/ */
virtual operator VALUE() const { virtual operator VALUE() const {
if (handle.IsEmpty()) { if (handle.IsEmpty()) {
return Qnil; return Qnil;
@ -63,8 +64,8 @@ namespace rr {
} }
/* /*
* Coerce a Ref into a v8::Local. * Coerce a Ref into a v8::Local.
*/ */
inline operator v8::Handle<T>() const { inline operator v8::Handle<T>() const {
return handle; return handle;
} }
@ -80,11 +81,11 @@ namespace rr {
} }
/* /*
* Pointer de-reference operators, this lets you use a ref to * Pointer de-reference operators, this lets you use a ref to
* call through to underlying v8 methods. e.g * call through to underlying v8 methods. e.g
* *
* Ref<v8::Object>(value)->ToString(); * Ref<v8::Object>(value)->ToString();
*/ */
inline v8::Handle<T> operator->() const { return *this; } inline v8::Handle<T> operator->() const { return *this; }
inline v8::Handle<T> operator*() const { return *this; } inline v8::Handle<T> operator*() const { return *this; }