mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-11 16:42:32 -05:00
wip
This commit is contained in:
parent
c7eb95df04
commit
5b927b82af
3 changed files with 65 additions and 46 deletions
46
src/main.rs
46
src/main.rs
|
@ -7,7 +7,6 @@ mod v8;
|
||||||
mod example {
|
mod example {
|
||||||
use crate::support::UniquePtr;
|
use crate::support::UniquePtr;
|
||||||
use crate::v8::inspector::channel::*;
|
use crate::v8::inspector::channel::*;
|
||||||
use crate::v8::platform::task::*;
|
|
||||||
use crate::v8::*;
|
use crate::v8::*;
|
||||||
|
|
||||||
pub struct TestChannel {
|
pub struct TestChannel {
|
||||||
|
@ -47,43 +46,9 @@ mod example {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestTask {
|
|
||||||
a: i32,
|
|
||||||
base: TaskBase,
|
|
||||||
b: i32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskImpl for TestTask {
|
fn main() {
|
||||||
fn base(&self) -> &TaskBase {
|
|
||||||
&self.base
|
|
||||||
}
|
|
||||||
fn base_mut(&mut self) -> &mut TaskBase {
|
|
||||||
&mut self.base
|
|
||||||
}
|
|
||||||
fn Run(&mut self) -> () {
|
|
||||||
println!("TestTask::Run {} {}", self.a, self.b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestTask {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
base: TaskBase::new::<Self>(),
|
|
||||||
a: 2,
|
|
||||||
b: 3,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for TestTask {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
println!("TestTask::drop()");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main1() {
|
|
||||||
use crate::v8::inspector::channel::*;
|
use crate::v8::inspector::channel::*;
|
||||||
use crate::v8::*;
|
use crate::v8::*;
|
||||||
use example::*;
|
use example::*;
|
||||||
|
@ -94,12 +59,3 @@ fn main1() {
|
||||||
let message = StringBuffer::create(&message);
|
let message = StringBuffer::create(&message);
|
||||||
chan.sendResponse(3, message);
|
chan.sendResponse(3, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
|
||||||
use crate::v8::platform::task::*;
|
|
||||||
use example::*;
|
|
||||||
let mut v = TestTask::new();
|
|
||||||
v.Run();
|
|
||||||
let b = Box::new(v);
|
|
||||||
b.into_unique_ptr();
|
|
||||||
}
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ impl<F> FieldOffset<F> {
|
||||||
let field_addr = field_ptr as usize;
|
let field_addr = field_ptr as usize;
|
||||||
assert!(field_addr >= embedder_addr);
|
assert!(field_addr >= embedder_addr);
|
||||||
assert!((field_addr + size_of::<F>()) <= (embedder_addr + size_of::<E>()));
|
assert!((field_addr + size_of::<F>()) <= (embedder_addr + size_of::<E>()));
|
||||||
Self(embedder_addr - field_addr, PhantomData)
|
Self(field_addr - embedder_addr, PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn to_embedder<E>(self, field: &F) -> &E {
|
pub unsafe fn to_embedder<E>(self, field: &F) -> &E {
|
||||||
|
|
|
@ -160,3 +160,66 @@ impl TaskBase {
|
||||||
std::mem::transmute(Self::dispatch_mut(task))
|
std::mem::transmute(Self::dispatch_mut(task))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
use std::sync::atomic::Ordering::SeqCst;
|
||||||
|
|
||||||
|
static RUN_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
static DROP_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
|
// Using repr(C) to preserve field ordering and test that everything works
|
||||||
|
// when the TaskBase field is not the first element of the struct.
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct TestTask {
|
||||||
|
f1: i32,
|
||||||
|
base: TaskBase,
|
||||||
|
f2: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestTask {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
base: TaskBase::new::<Self>(),
|
||||||
|
f1: 42,
|
||||||
|
f2: 4.2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TaskImpl for TestTask {
|
||||||
|
fn base(&self) -> &TaskBase {
|
||||||
|
&self.base
|
||||||
|
}
|
||||||
|
fn base_mut(&mut self) -> &mut TaskBase {
|
||||||
|
&mut self.base
|
||||||
|
}
|
||||||
|
fn Run(&mut self) -> () {
|
||||||
|
RUN_COUNT.fetch_add(1, SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for TestTask {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
DROP_COUNT.fetch_add(1, SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_v8_platform_task() {
|
||||||
|
{
|
||||||
|
let mut v = TestTask::new();
|
||||||
|
v.Run();
|
||||||
|
}
|
||||||
|
assert_eq!(RUN_COUNT.swap(0, SeqCst), 1);
|
||||||
|
assert_eq!(DROP_COUNT.swap(0, SeqCst), 1);
|
||||||
|
|
||||||
|
{
|
||||||
|
let b = Box::new(TestTask::new());
|
||||||
|
b.into_unique_ptr();
|
||||||
|
}
|
||||||
|
assert_eq!(RUN_COUNT.swap(0, SeqCst), 0);
|
||||||
|
assert_eq!(DROP_COUNT.swap(0, SeqCst), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue