summaryrefslogtreecommitdiff
path: root/core/ops.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2020-05-29 17:41:39 -0400
committerGitHub <noreply@github.com>2020-05-29 17:41:39 -0400
commitd4b05dd89e94ed1bba5b24c683da0a895f2ce597 (patch)
tree7e098257f5558a624e1d691f92c4d6d4cef56667 /core/ops.rs
parent106b00173806e088472e123d04fdc8d260c3820d (diff)
refactor: Split isolate and state using safe get_slot() (#5929)
Diffstat (limited to 'core/ops.rs')
-rw-r--r--core/ops.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/core/ops.rs b/core/ops.rs
index 0361f5ee9..ecece7355 100644
--- a/core/ops.rs
+++ b/core/ops.rs
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-use crate::CoreIsolate;
+use crate::core_isolate::CoreIsolateState;
use crate::ZeroCopyBuf;
use futures::Future;
use std::collections::HashMap;
@@ -22,7 +22,7 @@ pub enum Op {
/// Main type describing op
pub type OpDispatcher =
- dyn Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static;
+ dyn Fn(&mut CoreIsolateState, &[u8], Option<ZeroCopyBuf>) -> Op + 'static;
#[derive(Default)]
pub struct OpRegistry {
@@ -33,8 +33,8 @@ pub struct OpRegistry {
impl OpRegistry {
pub fn new() -> Self {
let mut registry = Self::default();
- let op_id = registry.register("ops", |isolate, _, _| {
- let buf = isolate.op_registry.json_map();
+ let op_id = registry.register("ops", |state, _, _| {
+ let buf = state.op_registry.json_map();
Op::Sync(buf)
});
assert_eq!(op_id, 0);
@@ -43,7 +43,7 @@ impl OpRegistry {
pub fn register<F>(&mut self, name: &str, op: F) -> OpId
where
- F: Fn(&mut CoreIsolate, &[u8], Option<ZeroCopyBuf>) -> Op + 'static,
+ F: Fn(&mut CoreIsolateState, &[u8], Option<ZeroCopyBuf>) -> Op + 'static,
{
let op_id = self.dispatchers.len() as u32;
@@ -68,6 +68,7 @@ impl OpRegistry {
#[test]
fn test_op_registry() {
+ use crate::CoreIsolate;
use std::sync::atomic;
use std::sync::Arc;
let mut op_registry = OpRegistry::new();
@@ -86,10 +87,12 @@ fn test_op_registry() {
expected.insert("test".to_string(), 1);
assert_eq!(op_registry.name_to_id, expected);
- let mut isolate = CoreIsolate::new(crate::StartupData::None, false);
+ let isolate = CoreIsolate::new(crate::StartupData::None, false);
let dispatch = op_registry.get(test_id).unwrap();
- let res = dispatch(&mut isolate, &[], None);
+ let state_rc = CoreIsolate::state(&isolate);
+ let mut state = state_rc.borrow_mut();
+ let res = dispatch(&mut state, &[], None);
if let Op::Sync(buf) = res {
assert_eq!(buf.len(), 0);
} else {
@@ -102,6 +105,7 @@ fn test_op_registry() {
#[test]
fn register_op_during_call() {
+ use crate::CoreIsolate;
use std::sync::atomic;
use std::sync::Arc;
use std::sync::Mutex;
@@ -126,13 +130,17 @@ fn register_op_during_call() {
};
assert!(test_id != 0);
- let mut isolate = CoreIsolate::new(crate::StartupData::None, false);
+ let isolate = CoreIsolate::new(crate::StartupData::None, false);
let dispatcher1 = {
let g = op_registry.lock().unwrap();
g.get(test_id).unwrap()
};
- dispatcher1(&mut isolate, &[], None);
+ {
+ let state_rc = CoreIsolate::state(&isolate);
+ let mut state = state_rc.borrow_mut();
+ dispatcher1(&mut state, &[], None);
+ }
let mut expected = HashMap::new();
expected.insert("ops".to_string(), 0);
@@ -147,7 +155,9 @@ fn register_op_during_call() {
let g = op_registry.lock().unwrap();
g.get(2).unwrap()
};
- let res = dispatcher2(&mut isolate, &[], None);
+ let state_rc = CoreIsolate::state(&isolate);
+ let mut state = state_rc.borrow_mut();
+ let res = dispatcher2(&mut state, &[], None);
if let Op::Sync(buf) = res {
assert_eq!(buf.len(), 0);
} else {