mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
32 lines
No EOL
765 B
C++
32 lines
No EOL
765 B
C++
#include "rr.h"
|
|
|
|
namespace rr {
|
|
namespace {
|
|
VALUE New(VALUE StringClass, VALUE string) {
|
|
v8::HandleScope h;
|
|
return String::ToRuby(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
|
|
}
|
|
VALUE Utf8Value(VALUE self) {
|
|
v8::HandleScope h;
|
|
String str(self);
|
|
return rb_str_new(*v8::String::Utf8Value(str), str->Utf8Length());
|
|
}
|
|
}
|
|
|
|
VALUE String::ToRuby(v8::Handle<v8::String> string) {
|
|
return String::create(string, String::Class);
|
|
}
|
|
|
|
String::operator v8::Handle<v8::Value>() {
|
|
return this->GetHandle();
|
|
}
|
|
|
|
VALUE String::Class;
|
|
|
|
void String::Init() {
|
|
rb_gc_register_address(&Class);
|
|
Class = defineClass("String");
|
|
RR_DEFINE_SINGLETON_METHOD(Class, "New", &New, 1);
|
|
RR_DEFINE_METHOD(Class, "Utf8Value", &Utf8Value, 0);
|
|
}
|
|
} |