Replace the lazy_static crate whth std::sync::LazyLock in components/script (#33004)

* replace in str.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace navigator.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace htmlmetaelement.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace document.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace cssstyledeclaration.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace script_runtime.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace window_named_properties.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* reduce dependency lazy_static

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* reduce lazy in script_runtime.rs

 `Mutex::new()`  is const contexts. I think that `JS_ENGINE` is need not lazy initialize.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

---------

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
This commit is contained in:
Hayashi Mikihiro 2024-08-12 16:30:35 +09:00 committed by GitHub
parent f38d1574bc
commit a797969efe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 98 additions and 104 deletions

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::ptr;
use std::sync::LazyLock;
use js::conversions::jsstr_to_string;
use js::glue::{AppendToIdVector, CreateProxyHandler, NewProxyObject, ProxyTraps};
@ -32,48 +33,48 @@ use crate::script_runtime::JSContext as SafeJSContext;
struct SyncWrapper(*const libc::c_void);
#[allow(unsafe_code)]
unsafe impl Sync for SyncWrapper {}
#[allow(unsafe_code)]
unsafe impl Send for SyncWrapper {}
lazy_static::lazy_static! {
static ref HANDLER: SyncWrapper = {
let traps = ProxyTraps {
enter: None,
getOwnPropertyDescriptor: Some(get_own_property_descriptor),
defineProperty: Some(define_property),
ownPropertyKeys: Some(own_property_keys),
delete_: Some(delete),
enumerate: None,
getPrototypeIfOrdinary: Some(get_prototype_if_ordinary),
getPrototype: None,
setPrototype: None,
setImmutablePrototype: None,
preventExtensions: Some(prevent_extensions),
isExtensible: Some(is_extensible),
has: None,
get: None,
set: None,
call: None,
construct: None,
hasOwn: None,
getOwnEnumerablePropertyKeys: None,
nativeCall: None,
objectClassIs: None,
className: Some(class_name),
fun_toString: None,
boxedValue_unbox: None,
defaultValue: None,
trace: None,
finalize: None,
objectMoved: None,
isCallable: None,
isConstructor: None,
};
#[allow(unsafe_code)]
unsafe {
SyncWrapper(CreateProxyHandler(&traps, ptr::null()))
}
static HANDLER: LazyLock<SyncWrapper> = LazyLock::new(|| {
let traps = ProxyTraps {
enter: None,
getOwnPropertyDescriptor: Some(get_own_property_descriptor),
defineProperty: Some(define_property),
ownPropertyKeys: Some(own_property_keys),
delete_: Some(delete),
enumerate: None,
getPrototypeIfOrdinary: Some(get_prototype_if_ordinary),
getPrototype: None,
setPrototype: None,
setImmutablePrototype: None,
preventExtensions: Some(prevent_extensions),
isExtensible: Some(is_extensible),
has: None,
get: None,
set: None,
call: None,
construct: None,
hasOwn: None,
getOwnEnumerablePropertyKeys: None,
nativeCall: None,
objectClassIs: None,
className: Some(class_name),
fun_toString: None,
boxedValue_unbox: None,
defaultValue: None,
trace: None,
finalize: None,
objectMoved: None,
isCallable: None,
isConstructor: None,
};
}
#[allow(unsafe_code)]
unsafe {
SyncWrapper(CreateProxyHandler(&traps, ptr::null()))
}
});
#[allow(unsafe_code)]
unsafe extern "C" fn get_own_property_descriptor(