Sha256: d36b75f54b28c2f8a6e9631c125ca2d32a32b1a1d48b101de17543a58396a6ee

Contents?: true

Size: 1.62 KB

Versions: 70

Compression:

Stored size: 1.62 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;
    Handle<String> str = unwrap(self);
    return rb_str_new(*String::Utf8Value(str), str->Utf8Length());
  }
  VALUE Utf16Value(VALUE self) {
    //How are UTF16 strings represented in ruby 1.8, 1.9
    return Qnil;
  }
  VALUE AsciiValue(VALUE self) {
    HandleScope handles;
    Handle<String> str = unwrap(self);
    return rb_str_new(*String::AsciiValue(str), str->Length());
  }
}

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

70 entries across 70 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.7.4 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.7.3 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.7.2 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.7.1 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.7.0 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.9 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.8 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.7 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.6 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.5 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.4 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.3 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.2 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.1 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.6.0 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.5.17 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.5.16 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.5.15 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp
classiccms-0.5.14 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_string.cpp