diff --git a/ext/v8/rr.h b/ext/v8/rr.h index c9e6552..d207769 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -310,6 +310,7 @@ class String: public Ref { 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); diff --git a/ext/v8/string.cc b/ext/v8/string.cc index 6c5274f..adab7b7 100644 --- a/ext/v8/string.cc +++ b/ext/v8/string.cc @@ -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 diff --git a/lib/v8/conversion.rb b/lib/v8/conversion.rb index 9751738..b7e3721 100644 --- a/lib/v8/conversion.rb +++ b/lib/v8/conversion.rb @@ -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)