Sha256: f39d463b7ac1a0ec8b3fc41b2e41db7787fb2ae62121dd5f45e8753ea8382bc7

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

#include "v8.h"
#include "v8_handle.h"
#include "v8_value.h"
#include "v8_string.h"

using namespace v8;

namespace {  
  VALUE StringClass;
  
  Persistent<String>& unwrap(VALUE value) {
    return rr_v8_handle<String>(value);
  }
  VALUE New(VALUE string_class, VALUE data) {
    HandleScope handles;
    VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
    return rr_v8_handle_new(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str)));
  }
  VALUE NewSymbol(VALUE string_class, VALUE data) {
    HandleScope scope;
    VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
    return rr_v8_handle_new(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str)));
  }
  VALUE Utf8Value(VALUE self) {
    HandleScope handles;
    return rb_str_new2(*String::Utf8Value(unwrap(self)));
  }
  VALUE Utf16Value(VALUE self) {
    //How are UTF16 strings represented in ruby 1.8, 1.9
    return Qnil;
  }
  VALUE AsciiValue(VALUE self) {
    HandleScope handles;
    return rb_str_new2(*String::AsciiValue(unwrap(self)));
  }
}

VALUE rr_reflect_v8_string(Handle<Value> value) {
  return rr_v8_handle_new(StringClass, Handle<String>::Cast(value));
}

void rr_init_string() {
  StringClass = rr_define_class("String", rr_v8_value_class());
  rr_define_singleton_method(StringClass, "New", New, 1);
  rr_define_singleton_method(StringClass, "NewSymbol", NewSymbol, 1);
  rr_define_method(StringClass, "Utf8Value", Utf8Value, 0);
  rr_define_method(StringClass, "Utf16Value", Utf16Value, 0);
  rr_define_method(StringClass, "AsciiValue", AsciiValue, 0);
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
therubyracer-0.9.0beta7 ext/v8/v8_string.cpp
therubyracer-0.9.0beta6 ext/v8/v8_string.cpp
therubyracer-0.9.0beta5 ext/v8/v8_string.cpp
therubyracer-0.9.0beta4 ext/v8/v8_string.cpp
therubyracer-0.9.0beta3 ext/v8/v8_string.cpp
therubyracer-0.9.0beta2 ext/v8/v8_string.cpp
therubyracer-0.9.0beta1 ext/v8/v8_string.cpp