Skip to content

Commit a6ba8a2

Browse files
committed
Use wasm_bindgen getter attribute to access 'name' property
1 parent 4ab9b85 commit a6ba8a2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

worker-sys/src/types/durable_object/id.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ extern "C" {
77

88
#[wasm_bindgen(method, catch, js_name=toString)]
99
pub fn to_string(this: &DurableObjectId) -> Result<String, JsValue>;
10+
11+
#[wasm_bindgen(method, getter)]
12+
pub fn name(this: &DurableObjectId) -> Option<String>;
1013
}

worker/src/durable.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ impl ObjectId<'_> {
180180
/// The name that was used to create the `ObjectId` via [`id_from_name`](https://developers.cloudflare.com/durable-objects/api/namespace/#idfromname).
181181
/// `None` is returned if the `ObjectId` was constructed using [`unique_id`](https://developers.cloudflare.com/durable-objects/api/namespace/#newuniqueid).
182182
pub fn name(&self) -> Option<String> {
183-
js_sys::Reflect::get(&self.inner, &"name".into())
184-
.ok()
185-
.as_ref()
186-
.and_then(JsValue::as_string)
183+
self.inner.name()
187184
}
188185
}
189186

0 commit comments

Comments
 (0)