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

27 lines
650 B
C++
Raw Normal View History

2012-05-02 19:15:11 -04:00
#include "rr.h"
namespace rr {
VALUE String::Class;
void String::Init() {
rb_gc_register_address(&Class);
2012-05-04 01:04:01 -04:00
Class = ClassBuilder("String", "Value").
defineSingletonMethod("New", &New).
defineMethod("Utf8Value", &Utf8Value);
}
VALUE String::New(VALUE StringClass, VALUE string) {
return String::Convert(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
}
VALUE String::Utf8Value(VALUE self) {
String str(self);
return rb_str_new(*v8::String::Utf8Value(str.GetHandle()), str->Utf8Length());
2012-05-02 19:15:11 -04:00
}
VALUE String::Convert(v8::Handle<v8::String> string) {
2012-05-03 14:01:10 -04:00
return String::create(string, String::Class);
}
} //namespace rr