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

35 lines
1 KiB
C++
Raw Normal View History

2009-12-07 09:06:06 -05:00
#include "v8.h"
#include "v8_ref.h"
#include "v8_script.h"
using namespace v8;
namespace {
2010-06-02 09:10:24 -04:00
VALUE New(VALUE self, VALUE source, VALUE source_name) {
HandleScope scope;
Local<String> src(rr_rb2v8(source)->ToString());
Local<String> src_name(rr_rb2v8(source_name)->ToString());
return rr_v8_ref_create(self, Script::Compile(src, src_name));
}
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 rr_v8_ref_create(self, Script::Compile(src, src_name));
}
2009-12-07 09:06:06 -05: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
}
void rr_init_script() {
VALUE ScriptClass = rr_define_class("Script");
2010-06-02 09:10:24 -04:00
rr_define_singleton_method(ScriptClass, "New", New, 2);
rr_define_singleton_method(ScriptClass, "Compile", Compile, 2);
rr_define_method(ScriptClass, "Run", Run, 0);
}