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

upgrade to 4.5.x, add isolate.Dispose()

This commit is contained in:
Charles Lowell 2015-07-04 12:20:50 -05:00
parent e452e123fd
commit b11e514b56
7 changed files with 41 additions and 24 deletions

5
ext/v8/.dir-locals.el Normal file
View file

@ -0,0 +1,5 @@
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((c++-mode
(c-basic-offset . 2)))

View file

@ -2,10 +2,14 @@ require 'mkmf'
have_library('pthread')
have_library('objc') if RUBY_PLATFORM =~ /darwin/
$CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall"
$CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g"
$CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic"
$CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic" unless RUBY_PLATFORM =~ /darwin/
$CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or RUBY_PLATFORM =~ /darwin/
$CPPFLAGS += " -std=c++11"
$LDFLAGS += " -stdlib=libstdc++"
CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/
if CONFIG['warnflags']
@ -16,7 +20,7 @@ if enable_config('debug')
$CFLAGS += " -O0 -ggdb3"
end
LIBV8_COMPATIBILITY = '~> 3.31.0'
LIBV8_COMPATIBILITY = '~> 4.5.95'
begin
require 'rubygems'

View file

@ -1,4 +1,6 @@
// -*- mode: c++ -*-
#include "rr.h"
#include "isolate.h"
namespace rr {
@ -6,6 +8,7 @@ namespace rr {
ClassBuilder("Isolate").
defineSingletonMethod("New", &New).
defineMethod("Dispose", &Isolate::Dispose).
defineMethod("Equals", &rr::Isolate::PointerEquals).
store(&Class);
@ -15,9 +18,13 @@ namespace rr {
return Isolate(v8::Isolate::New());
}
VALUE Isolate::Dispose(VALUE self) {
Isolate(self)->Dispose();
return Qnil;
}
template <>
void Pointer<v8::Isolate>::unwrap(VALUE value) {
Data_Get_Struct(value, class v8::Isolate, pointer);
}
}

View file

@ -1,34 +1,32 @@
// -*- mode: c++ -*-
#ifndef RR_ISOLATE
#define RR_ISOLATE
namespace rr {
/**
* V8::C::Isolate
*
* Represents a fully encapsulated V8 virtual machine. Allocated
* from Ruby by calling `V8::C::Isolate::New()`
*
* Note: You must call `Dispose()` on the isolate for its resources
* to be released.
*/
class Isolate : public Pointer<v8::Isolate> {
public:
static void Init();
static VALUE New(VALUE self);
// TODO: Add a Dispose method
inline Isolate(v8::Isolate* isolate) : Pointer<v8::Isolate>(isolate) {}
inline Isolate(VALUE value) : Pointer<v8::Isolate>(value) {}
inline operator VALUE() {
return Data_Wrap_Struct(Class, 0, &release, pointer);
return Data_Wrap_Struct(Class, 0, 0, pointer);
}
static void release(v8::Isolate* isolate) {
// The isolates must be released with Dispose.
// Using the delete operator is not allowed.
// TODO: Do we want to dispose of the isolate when the object itself
// is garbage-collected?
// Can the isolate be used without it having a reference in ruby world?
// isolate->Dispose();
}
static VALUE Dispose(VALUE self);
};
}
#endif

View file

@ -116,7 +116,7 @@ namespace rr {
*
* Pointer<Greeter>(rubyValue)->sayHello();
*/
inline Pointer(VALUE v) : {
inline Pointer(VALUE v) {
if (RTEST(v)) {
this->unwrap(v);
} else {

View file

@ -1,15 +1,18 @@
require 'c_spec_helper'
describe V8::C::Isolate do
let(:isolate) { V8::C::Isolate::New() }
it 'can create a new isolate' do
expect(V8::C::Isolate.New).to be
expect(isolate).to be
end
it 'can be tested for equality' do
isolate_one = V8::C::Isolate.New
isolate_two = V8::C::Isolate.New
expect(isolate.Equals(isolate)).to eq true
expect(isolate.Equals(V8::C::Isolate::New())).to eq false
end
expect(isolate_one.Equals(isolate_one)).to eq true
expect(isolate_one.Equals(isolate_two)).to eq false
it "can be disposed of" do
isolate.Dispose()
end
end

View file

@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
gem.license = 'MIT'
gem.add_dependency 'ref'
gem.add_dependency 'libv8', '~> 3.16.14.0'
gem.add_dependency 'libv8', '~> 4.5.95.0'
end