2009-12-07 09:06:06 -05:00
|
|
|
#include "v8.h"
|
|
|
|
#include "v8_ref.h"
|
|
|
|
#include "v8_script.h"
|
2009-12-13 14:44:28 -05:00
|
|
|
#include "converters.h"
|
2009-12-07 09:06:06 -05:00
|
|
|
|
|
|
|
using namespace v8;
|
|
|
|
|
2010-05-18 06:27:23 -04:00
|
|
|
namespace {
|
|
|
|
VALUE Compile(VALUE self, VALUE source, VALUE source_name) {
|
|
|
|
Local<String> src(rr_rb2v8(source)->ToString());
|
|
|
|
Local<String> src_name(rr_rb2v8(source_name)->ToString());
|
|
|
|
return V8_Ref_Create(self, Script::Compile(src, src_name));
|
|
|
|
}
|
2009-12-07 09:06:06 -05:00
|
|
|
|
2010-05-18 06:27:23 -04:00
|
|
|
VALUE Run(VALUE self) {
|
|
|
|
Local<Script> script(V8_Ref_Get<Script>(self));
|
|
|
|
Local<Value> result(script->Run());
|
|
|
|
return result.IsEmpty() ? Qnil : rr_v82rb(result);
|
|
|
|
}
|
2009-12-07 09:06:06 -05:00
|
|
|
}
|
|
|
|
|
2010-05-18 06:27:23 -04:00
|
|
|
void rr_init_script() {
|
|
|
|
VALUE ScriptClass = rr_define_class("Script");
|
|
|
|
rr_define_singleton_method(ScriptClass, "Compile", Compile, 2);
|
|
|
|
rr_define_method(ScriptClass, "Run", Run, 0);
|
|
|
|
rb_funcall(ScriptClass, rb_intern("private_class_method"), 1, rb_str_new2("new"));
|
|
|
|
}
|