diff --git a/components/script/dom/cryptokey.rs b/components/script/dom/cryptokey.rs index 498199c586e..b710f27dee1 100644 --- a/components/script/dom/cryptokey.rs +++ b/components/script/dom/cryptokey.rs @@ -61,6 +61,11 @@ pub(crate) struct CryptoKey { /// usages: DomRefCell>, + + /// Cached object of + #[ignore_malloc_size_of = "Defined in mozjs"] + usages_object: Heap<*mut JSObject>, + #[no_trace] handle: Handle, } @@ -80,6 +85,7 @@ impl CryptoKey { algorithm, algorithm_object: Heap::default(), usages: DomRefCell::new(usages), + usages_object: Heap::default(), handle, } } @@ -99,7 +105,7 @@ impl CryptoKey { Box::new(CryptoKey::new_inherited( key_type, extractable, - usages, + usages.clone(), algorithm, handle, )), @@ -109,6 +115,12 @@ impl CryptoKey { object.algorithm_object.set(algorithm_object.get()); + // Create and store a cached object of usages + let cx = GlobalScope::get_cx(); + rooted!(in(*cx) let mut usages_object_value: Value); + usages.safe_to_jsval(cx, usages_object_value.handle_mut()); + object.usages_object.set(usages_object_value.to_object()); + object } @@ -130,6 +142,12 @@ impl CryptoKey { pub(crate) fn set_usages(&self, usages: &[KeyUsage]) { *self.usages.borrow_mut() = usages.to_owned(); + + // Create and store a cached object of usages + let cx = GlobalScope::get_cx(); + rooted!(in(*cx) let mut usages_object_value: Value); + usages.safe_to_jsval(cx, usages_object_value.handle_mut()); + self.usages_object.set(usages_object_value.to_object()); } } @@ -150,10 +168,8 @@ impl CryptoKeyMethods for CryptoKey { } /// - fn Usages(&self, cx: JSContext) -> NonNull { - rooted!(in(*cx) let mut usages: Value); - self.usages.borrow().safe_to_jsval(cx, usages.handle_mut()); - NonNull::new(usages.to_object()).unwrap() + fn Usages(&self, _cx: JSContext) -> NonNull { + NonNull::new(self.usages_object.get()).unwrap() } } diff --git a/tests/wpt/meta/WebCryptoAPI/crypto_key_cached_slots.https.any.js.ini b/tests/wpt/meta/WebCryptoAPI/crypto_key_cached_slots.https.any.js.ini deleted file mode 100644 index 93a3f72e5b5..00000000000 --- a/tests/wpt/meta/WebCryptoAPI/crypto_key_cached_slots.https.any.js.ini +++ /dev/null @@ -1,8 +0,0 @@ -[crypto_key_cached_slots.https.any.worker.html] - [CryptoKey.usages getter returns cached object] - expected: FAIL - - -[crypto_key_cached_slots.https.any.html] - [CryptoKey.usages getter returns cached object] - expected: FAIL