0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

clean up example in docs

This commit is contained in:
Ryan Dahl 2019-12-27 11:14:54 -05:00 committed by Ry Dahl
parent eee7f98108
commit 61c74ec0e7

View file

@ -1,43 +1,36 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
//! # Hello World Example
//! # Example
//!
//! ```
//! use rusty_v8::{Isolate, V8, HandleScope, Script, Context, Locker, Local};
//! use rusty_v8::{platform, new_default_allocator};
//! use rusty_v8 as v8;
//!
//! 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 platform = v8::platform::new_default_platform();
//! v8::V8::initialize_platform(platform);
//! v8::V8::initialize();
//!
//! let mut create_params = v8::Isolate::create_params();
//! create_params.set_array_buffer_allocator(v8::new_default_allocator());
//! let isolate = v8::Isolate::new(create_params);
//! let mut locker = v8::Locker::new(&isolate);
//! {
//! let mut handle_scope = HandleScope::new(&mut locker);
//! let mut handle_scope = v8::HandleScope::new(&mut locker);
//! let scope = handle_scope.enter();
//!
//! let mut context = Context::new(scope);
//! let mut context = v8::Context::new(scope);
//! context.enter();
//! let code = rusty_v8::String::new(scope, "'Hello World!'").unwrap();
//!
//! let code = v8::String::new(scope, "'Hello' + ' World!'").unwrap();
//! code.to_rust_string_lossy(scope);
//! let mut script = Script::compile(scope, context, code, None).unwrap();
//! let mut script = v8::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 result: v8::Local<v8::String> = unsafe { std::mem::transmute_copy(&result) };
//! let str = result.to_rust_string_lossy(scope);
//!
//! println!("{}", str);
//!
//! context.exit();
//! }
//!
//! drop(locker);
//!
//! ```
//!
#![allow(clippy::missing_safety_doc)]
#![allow(dead_code)]