Class: V8::Context
Direct Known Subclasses
Instance Attribute Summary collapse
- #error ⇒ Object readonly
- #errors ⇒ Object readonly
Class Method Summary collapse
-
.V8::Context.new ⇒ Object
Returns new V8 context.
Instance Method Summary collapse
-
#enter ⇒ Object
Enters to context.
-
#entered? ⇒ Boolean
Returns
true
when this context is entered. -
#eval(source, filename) ⇒ Object
Evaluates given JavaScript code within current context.
-
#evaluate(source, filename) ⇒ Object
Evaluates given JavaScript code within current context.
-
#exit ⇒ nil
Exits from context.
- #get(key) ⇒ Object (also: #[])
-
#global ⇒ Object
Returns global object for this context.
-
#prototype ⇒ Object
Returns prototype object of current context.
- #set(key, value) ⇒ Object (also: #[]=)
Class Method Details
.V8::Context.new ⇒ Object
Returns new V8 context.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'ext/v8/v8_context.cpp', line 21
static VALUE rb_v8_context_new(VALUE self)
{
HandleScope scope;
Persistent<Context> context(Context::New());
VALUE ref = v8_ref_new(self, context);
rb_iv_set(ref, "@errors", rb_ary_new());
context.Dispose();
return ref;
}
|
Instance Method Details
#enter ⇒ Boolean #enter {|cxt| ... } ⇒ nil
Enters to context. Returns true
when enter action has been performed. If current context is already entered then returns false
.
If block passed then context enters only for block execution, and exits imidietely after that.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'ext/v8/v8_context.cpp', line 46
static VALUE rb_v8_context_enter(VALUE self)
{
HandleScope scope;
Handle<Context> context = unwrap(self);
VALUE entered = Qfalse;
if (Context::GetEntered() != context) {
context->Enter();
entered = Qtrue;
}
if (rb_block_given_p()) {
rb_yield(self);
context->Exit();
return Qnil;
}
return entered;
}
|
#entered? ⇒ Boolean
Returns true
when this context is entered.
153 154 155 156 157 |
# File 'ext/v8/v8_context.cpp', line 153
static VALUE rb_v8_context_entered_p(VALUE self)
{
HandleScope scope;
return unwrap(self) == Context::GetEntered() ? Qtrue : Qfalse;
}
|
#eval(source, filename) ⇒ Object #evaluate(source, filename) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'ext/v8/v8_context.cpp', line 80
static VALUE rb_v8_context_evaluate(VALUE self, VALUE source, VALUE filename)
{
HandleScope scope;
Local<String> _source(String::Cast(*to_v8(source)));
Local<String> _filename(String::Cast(*to_v8(filename)));
rb_v8_context_enter(self);
rb_iv_set(self, "@error", Qfalse);
TryCatch try_catch;
Local<Script> script = Script::Compile(_source, _filename);
if (!try_catch.HasCaught()) {
Local<Value> result = script->Run();
if (!try_catch.HasCaught()) {
return to_ruby(result);
}
}
return rb_v8_error_new3(try_catch);
}
|
#eval(source, filename) ⇒ Object #evaluate(source, filename) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'ext/v8/v8_context.cpp', line 80
static VALUE rb_v8_context_evaluate(VALUE self, VALUE source, VALUE filename)
{
HandleScope scope;
Local<String> _source(String::Cast(*to_v8(source)));
Local<String> _filename(String::Cast(*to_v8(filename)));
rb_v8_context_enter(self);
rb_iv_set(self, "@error", Qfalse);
TryCatch try_catch;
Local<Script> script = Script::Compile(_source, _filename);
if (!try_catch.HasCaught()) {
Local<Value> result = script->Run();
if (!try_catch.HasCaught()) {
return to_ruby(result);
}
}
return rb_v8_error_new3(try_catch);
}
|
#exit ⇒ nil
Exits from context.
139 140 141 142 143 144 |
# File 'ext/v8/v8_context.cpp', line 139
static VALUE rb_v8_context_exit(VALUE self)
{
HandleScope scope;
unwrap(self)->Exit();
return Qnil;
}
|
#get(key) ⇒ Object Also known as: []
3 4 5 |
# File 'lib/v8/context.rb', line 3 def get(key) prototype[key] end |
#global ⇒ Object
Returns global object for this context.
125 126 127 128 129 130 |
# File 'ext/v8/v8_context.cpp', line 125
static VALUE rb_v8_context_global(VALUE self)
{
HandleScope scope;
Handle<Value> global = unwrap(self)->Global();
return to_ruby(global);
}
|
#prototype ⇒ Object
Returns prototype object of current context.
111 112 113 114 115 116 |
# File 'ext/v8/v8_context.cpp', line 111
VALUE rb_v8_context_prototype(VALUE self)
{
HandleScope scope;
Handle<Object> proto(Object::Cast(*unwrap(self)->Global()->GetPrototype()));
return to_ruby(proto);
}
|
#set(key, value) ⇒ Object Also known as: []=
8 9 10 |
# File 'lib/v8/context.rb', line 8 def set(key, value) prototype[key] = value end |