summaryrefslogtreecommitdiff
path: root/core/ops.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-12-16 17:14:12 +0100
committerGitHub <noreply@github.com>2020-12-16 17:14:12 +0100
commit6984b63f2f3c8d0819fe2dced8252a81f3400ae7 (patch)
tree5201bc962f913927409ae2770aca48ffa3aaaa34 /core/ops.rs
parent9fe26f8ca189ac81d9c20c454b9dbfa5e1011c3f (diff)
refactor: rewrite ops to use ResourceTable2 (#8512)
This commit migrates all ops to use new resource table and "AsyncRefCell". Old implementation of resource table was completely removed and all code referencing it was updated to use new system.
Diffstat (limited to 'core/ops.rs')
-rw-r--r--core/ops.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/core/ops.rs b/core/ops.rs
index bf10d3d86..2907d2552 100644
--- a/core/ops.rs
+++ b/core/ops.rs
@@ -4,6 +4,8 @@ use crate::error::bad_resource_id;
use crate::error::type_error;
use crate::error::AnyError;
use crate::gotham_state::GothamState;
+use crate::resources::ResourceTable;
+use crate::runtime::GetErrorClassFn;
use crate::BufVec;
use crate::ZeroCopyBuf;
use futures::Future;
@@ -33,10 +35,9 @@ pub enum Op {
/// Maintains the resources and ops inside a JS runtime.
pub struct OpState {
- pub resource_table: crate::ResourceTable,
- pub resource_table_2: crate::resources2::ResourceTable,
+ pub resource_table: ResourceTable,
pub op_table: OpTable,
- pub get_error_class_fn: crate::runtime::GetErrorClassFn,
+ pub get_error_class_fn: GetErrorClassFn,
gotham_state: GothamState,
}
@@ -47,7 +48,6 @@ impl Default for OpState {
fn default() -> OpState {
OpState {
resource_table: Default::default(),
- resource_table_2: Default::default(),
op_table: OpTable::default(),
get_error_class_fn: &|_| "Error",
gotham_state: Default::default(),
@@ -279,7 +279,11 @@ pub fn op_resources(
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
- let serialized_resources = state.resource_table.entries();
+ let serialized_resources: HashMap<u32, String> = state
+ .resource_table
+ .names()
+ .map(|(rid, name)| (rid, name.to_string()))
+ .collect();
Ok(json!(serialized_resources))
}
@@ -300,5 +304,6 @@ pub fn op_close(
.resource_table
.close(rid as u32)
.ok_or_else(bad_resource_id)?;
+
Ok(json!({}))
}