2009-12-07 09:20:16 +02:00
|
|
|
#include "v8_cxt.h"
|
2009-12-18 09:48:06 +02:00
|
|
|
#include "v8_msg.h"
|
|
|
|
#include "converters.h"
|
2009-12-07 09:20:16 +02:00
|
|
|
|
|
|
|
using namespace v8;
|
|
|
|
|
2009-12-11 19:11:05 +02:00
|
|
|
VALUE v8_Context_New(int argc, VALUE *argv, VALUE self) {
|
|
|
|
HandleScope handles;
|
|
|
|
VALUE scope;
|
|
|
|
rb_scan_args(argc,argv, "01", &scope);
|
|
|
|
if (NIL_P(scope)) {
|
|
|
|
return V8_Ref_Create(self, Context::New());
|
|
|
|
} else {
|
2009-12-13 17:08:55 +02:00
|
|
|
Local<ObjectTemplate> t = V8_Ref_Get<ObjectTemplate>(scope);
|
2009-12-11 19:11:05 +02:00
|
|
|
return V8_Ref_Create(self, Context::New(0, t));
|
|
|
|
}
|
2009-12-07 16:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE v8_cxt_Global(VALUE self) {
|
2009-12-18 09:48:06 +02:00
|
|
|
HandleScope handles;
|
|
|
|
convert_v8_to_rb_t v82rb;
|
2009-12-13 17:08:55 +02:00
|
|
|
Local<Context> cxt = V8_Ref_Get<Context>(self);
|
2009-12-18 09:48:06 +02:00
|
|
|
Local<Value> global = *cxt->Global();
|
|
|
|
return v82rb(global);
|
2009-12-07 16:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE v8_cxt_open(VALUE self) {
|
|
|
|
HandleScope handles;
|
2009-12-18 09:48:06 +02:00
|
|
|
TryCatch exceptions;
|
2009-12-13 17:08:55 +02:00
|
|
|
Local<Context> cxt = V8_Ref_Get<Context>(self);
|
2009-12-07 16:06:06 +02:00
|
|
|
Context::Scope enter(cxt);
|
|
|
|
if (rb_block_given_p()) {
|
2009-12-18 09:48:06 +02:00
|
|
|
printf("<div>About to execute Ruby Block</div>");
|
|
|
|
VALUE result = rb_yield(self);
|
|
|
|
printf("<div>Ruby Block was executed</div>\n");
|
|
|
|
if (exceptions.HasCaught()) {
|
|
|
|
return V8_Wrap_Message(exceptions.Message());
|
|
|
|
} else {
|
|
|
|
printf("<div>No exception</div>");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return result;
|
2009-12-07 16:06:06 +02:00
|
|
|
} else {
|
2009-12-18 09:48:06 +02:00
|
|
|
printf("<div>No block given!</div>");
|
2009-12-07 16:06:06 +02:00
|
|
|
return Qnil;
|
|
|
|
}
|
2009-12-07 09:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|