2019-11-01 13:50:12 -04:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2019-12-27 19:41:44 +08:00
|
|
|
//! # Hello World Example
|
|
|
|
//!
|
|
|
|
//! ```
|
|
|
|
//! use rusty_v8::{Isolate, V8, HandleScope, Script, Context, Locker, Local};
|
|
|
|
//! use rusty_v8::{platform, new_default_allocator};
|
|
|
|
//!
|
|
|
|
//! let platform = platform::new_default_platform();
|
|
|
|
//! V8::initialize_platform(platform);
|
|
|
|
//! V8::initialize();
|
|
|
|
//!
|
|
|
|
//! let mut create_params = Isolate::create_params();
|
|
|
|
//! create_params.set_array_buffer_allocator(new_default_allocator());
|
|
|
|
//! let isolate = Isolate::new(create_params);
|
|
|
|
//! let mut locker = Locker::new(&isolate);
|
|
|
|
//!
|
|
|
|
//! {
|
|
|
|
//! let mut handle_scope = HandleScope::new(&mut locker);
|
|
|
|
//! let scope = handle_scope.enter();
|
|
|
|
//!
|
|
|
|
//! let mut context = Context::new(scope);
|
|
|
|
//! context.enter();
|
|
|
|
//! let code = rusty_v8::String::new(scope, "'Hello World!'").unwrap();
|
|
|
|
//! code.to_rust_string_lossy(scope);
|
|
|
|
//! let mut script = Script::compile(scope, context, code, None).unwrap();
|
|
|
|
//! let result = script.run(scope, context).unwrap();
|
|
|
|
//! let result: Local<rusty_v8::String> = unsafe { std::mem::transmute_copy(&result) };
|
|
|
|
//!
|
|
|
|
//! let str = result.to_rust_string_lossy(scope);
|
|
|
|
//!
|
|
|
|
//! println!("{}", str);
|
|
|
|
//!
|
|
|
|
//! context.exit();
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! drop(locker);
|
|
|
|
//!
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
|
2019-11-15 16:21:34 -08:00
|
|
|
#![allow(clippy::missing_safety_doc)]
|
2019-10-22 22:58:11 -07:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2019-12-04 08:03:17 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bitflags;
|
2019-11-15 16:21:34 -08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2019-11-15 12:57:34 -05:00
|
|
|
extern crate libc;
|
|
|
|
|
2019-12-21 08:50:59 -05:00
|
|
|
mod array_buffer;
|
2019-12-25 00:31:36 +01:00
|
|
|
mod callback_scope;
|
2019-12-04 14:12:27 +01:00
|
|
|
mod context;
|
2019-12-09 02:26:58 +01:00
|
|
|
mod exception;
|
2019-12-11 04:43:22 +01:00
|
|
|
mod function;
|
2019-12-21 18:17:03 +01:00
|
|
|
mod global;
|
2019-12-04 00:57:06 -05:00
|
|
|
mod handle_scope;
|
|
|
|
mod isolate;
|
|
|
|
mod local;
|
|
|
|
mod locker;
|
2019-12-20 14:56:32 +01:00
|
|
|
mod module;
|
2019-12-04 08:03:17 +01:00
|
|
|
mod number;
|
2019-12-10 01:14:07 +01:00
|
|
|
mod object;
|
2019-12-21 06:38:26 -05:00
|
|
|
mod primitive_array;
|
2019-12-05 17:03:18 -05:00
|
|
|
mod primitives;
|
2019-12-14 02:18:30 +01:00
|
|
|
mod promise;
|
2019-12-20 18:16:44 +01:00
|
|
|
mod property;
|
2019-12-04 14:12:27 +01:00
|
|
|
mod script;
|
2019-12-21 06:38:26 -05:00
|
|
|
mod script_or_module;
|
2019-12-24 14:03:32 +01:00
|
|
|
mod snapshot;
|
2019-12-04 10:10:15 -05:00
|
|
|
mod string;
|
2019-12-04 00:57:06 -05:00
|
|
|
mod support;
|
2019-12-21 00:28:08 +01:00
|
|
|
mod try_catch;
|
2019-12-25 20:37:25 -05:00
|
|
|
mod uint8_array;
|
2019-12-06 09:36:34 -05:00
|
|
|
mod value;
|
2019-12-04 00:57:06 -05:00
|
|
|
|
2019-12-24 05:50:30 -05:00
|
|
|
pub mod array_buffer_view;
|
2019-12-04 10:31:54 -05:00
|
|
|
pub mod inspector;
|
2019-12-20 08:47:20 -05:00
|
|
|
pub mod json;
|
2019-10-22 14:52:43 -07:00
|
|
|
pub mod platform;
|
2019-12-25 00:31:36 +01:00
|
|
|
pub mod scope;
|
2019-12-20 14:54:20 -05:00
|
|
|
pub mod script_compiler;
|
2019-11-30 08:47:26 -08:00
|
|
|
// This module is intentionally named "V8" rather than "v8" to match the
|
|
|
|
// C++ namespace "v8::V8".
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub mod V8;
|
2019-10-17 16:46:54 -07:00
|
|
|
|
2019-12-25 10:56:27 -05:00
|
|
|
pub use array_buffer::*;
|
2019-12-25 00:31:36 +01:00
|
|
|
pub use callback_scope::CallbackScope;
|
2019-12-04 14:12:27 +01:00
|
|
|
pub use context::Context;
|
2019-12-20 08:47:20 -05:00
|
|
|
pub use exception::*;
|
2019-12-20 18:16:44 +01:00
|
|
|
pub use function::{
|
|
|
|
Function, FunctionCallbackInfo, FunctionTemplate, ReturnValue,
|
|
|
|
};
|
2019-12-21 18:17:03 +01:00
|
|
|
pub use global::Global;
|
2019-12-25 00:31:36 +01:00
|
|
|
pub use handle_scope::{EscapableHandleScope, HandleScope, ToLocal};
|
2019-12-26 10:45:55 -05:00
|
|
|
pub use isolate::*;
|
2019-11-30 16:31:51 +01:00
|
|
|
pub use local::Local;
|
2019-11-15 16:21:34 -08:00
|
|
|
pub use locker::Locker;
|
2019-12-23 20:23:55 -05:00
|
|
|
pub use module::*;
|
2019-12-04 08:03:17 +01:00
|
|
|
pub use number::{Integer, Number};
|
2019-12-10 01:14:07 +01:00
|
|
|
pub use object::Object;
|
2019-12-21 06:38:26 -05:00
|
|
|
pub use primitive_array::PrimitiveArray;
|
2019-12-05 17:03:18 -05:00
|
|
|
pub use primitives::*;
|
2019-12-19 14:13:33 +01:00
|
|
|
pub use promise::{
|
|
|
|
Promise, PromiseRejectEvent, PromiseRejectMessage, PromiseResolver,
|
|
|
|
PromiseState,
|
|
|
|
};
|
2019-12-20 18:16:44 +01:00
|
|
|
pub use property::PropertyCallbackInfo;
|
2019-12-04 14:12:27 +01:00
|
|
|
pub use script::{Script, ScriptOrigin};
|
2019-12-21 06:38:26 -05:00
|
|
|
pub use script_or_module::ScriptOrModule;
|
2019-12-24 14:03:32 +01:00
|
|
|
pub use snapshot::{FunctionCodeHandling, SnapshotCreator, StartupData};
|
2019-12-04 10:10:15 -05:00
|
|
|
pub use string::NewStringType;
|
2019-12-04 08:03:17 +01:00
|
|
|
pub use string::String;
|
2019-12-24 16:10:40 -05:00
|
|
|
pub use support::MaybeBool;
|
2019-12-26 03:32:22 +01:00
|
|
|
pub use support::SharedRef;
|
2019-12-24 16:10:40 -05:00
|
|
|
pub use support::UniqueRef;
|
2019-12-21 04:00:17 +01:00
|
|
|
pub use try_catch::{TryCatch, TryCatchScope};
|
2019-12-25 20:37:25 -05:00
|
|
|
pub use uint8_array::Uint8Array;
|
2019-12-06 09:36:34 -05:00
|
|
|
pub use value::Value;
|