0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-03-10 14:06:53 -04:00
rusty-v8/src/context.rs

47 lines
1.4 KiB
Rust
Raw Normal View History

use crate::isolate::Isolate;
2019-12-04 14:12:27 +01:00
use crate::support::Opaque;
use crate::Local;
2019-12-11 04:43:22 +01:00
use crate::Object;
2019-12-04 14:12:27 +01:00
extern "C" {
2019-12-19 20:11:22 -05:00
fn v8__Context__New(isolate: &Isolate) -> *mut Context;
2019-12-04 14:12:27 +01:00
fn v8__Context__Enter(this: &mut Context);
fn v8__Context__Exit(this: &mut Context);
fn v8__Context__GetIsolate(this: &mut Context) -> *mut Isolate;
2019-12-11 04:43:22 +01:00
fn v8__Context__Global(this: *mut Context) -> *mut Object;
2019-12-04 14:12:27 +01:00
}
#[repr(C)]
pub struct Context(Opaque);
impl Context {
pub fn new(isolate: &Isolate) -> Local<Context> {
2019-12-04 14:12:27 +01:00
// TODO: optional arguments;
2019-12-19 20:11:22 -05:00
unsafe { Local::from_raw(v8__Context__New(isolate)).unwrap() }
2019-12-04 14:12:27 +01:00
}
2019-12-11 04:43:22 +01:00
/// Returns the global proxy object.
///
/// Global proxy object is a thin wrapper whose prototype points to actual
/// context's global object with the properties like Object, etc. This is done
/// that way for security reasons (for more details see
/// https://wiki.mozilla.org/Gecko:SplitWindow).
///
/// Please note that changes to global proxy object prototype most probably
/// would break VM---v8 expects only global object as a prototype of global
/// proxy object.
pub fn global(&mut self) -> Local<Object> {
2019-12-11 04:43:22 +01:00
unsafe { Local::from_raw(v8__Context__Global(&mut *self)).unwrap() }
}
2019-12-04 14:12:27 +01:00
pub fn enter(&mut self) {
// TODO: enter/exit should be controlled by a scope.
unsafe { v8__Context__Enter(self) };
}
pub fn exit(&mut self) {
// TODO: enter/exit should be controlled by a scope.
unsafe { v8__Context__Exit(self) };
}
}