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

convert symbols to v8

This commit is contained in:
Charles Lowell 2012-06-08 08:51:10 -05:00
parent 9b461020a5
commit e097a20917
3 changed files with 12 additions and 0 deletions

View file

@ -310,6 +310,7 @@ class String: public Ref<v8::String> {
public:
static void Init();
static VALUE New(VALUE self, VALUE value);
static VALUE NewSymbol(VALUE self, VALUE string);
static VALUE Utf8Value(VALUE self);
static VALUE Concat(VALUE self, VALUE left, VALUE right);

View file

@ -5,6 +5,7 @@ namespace rr {
void String::Init() {
ClassBuilder("String", Primitive::Class).
defineSingletonMethod("New", &New).
defineSingletonMethod("NewSymbol", &NewSymbol).
defineSingletonMethod("Concat", &Concat).
defineMethod("Utf8Value", &Utf8Value).
store(&Class);
@ -14,6 +15,10 @@ VALUE String::New(VALUE StringClass, VALUE string) {
return String(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
}
VALUE String::NewSymbol(VALUE self, VALUE string) {
return String(v8::String::NewSymbol(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
}
VALUE String::Utf8Value(VALUE self) {
String str(self);
#ifdef HAVE_RUBY_ENCODING_H

View file

@ -26,6 +26,12 @@ class String
end
end
class Symbol
def to_v8
V8::C::String::NewSymbol(to_s)
end
end
class V8::C::Date
def to_ruby
Time.at(self.NumberValue() / 1000)