aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings
diff options
context:
space:
mode:
authoreri <eri@inventati.org>2024-03-21 14:38:16 +0100
committerGitHub <noreply@github.com>2024-03-21 13:38:16 +0000
commit8c7e9a15e1d63f99a887f4c78638017e31eed7a0 (patch)
tree0fbb761a673fccb4f495f4f4fe29997e897ad641 /components/script/dom/bindings
parentf5c4988dcb320bd92555d756790576ae36d74f81 (diff)
downloadservo-8c7e9a15e1d63f99a887f4c78638017e31eed7a0.tar.gz
servo-8c7e9a15e1d63f99a887f4c78638017e31eed7a0.zip
Remove repeated imports from generated code (#31711)
* feat: try to deduplicate imports in codegen * feat: another attempt * feat: start testing imports * feat: clean all global imports * feat: remove shared imports from CGDescriptor * feat: remove redundant imports from CGDescriptor * fix: formatting * fix: remove libc (base level import) * feat: roll back named path changes * feat: last changes and tidy * experiment: move imports into a separate file * fix: extra parenthesis * fix: remove repeated allow statement
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py396
-rw-r--r--components/script/dom/bindings/import.rs146
-rw-r--r--components/script/dom/bindings/mod.rs1
-rw-r--r--components/script/dom/bindings/utils.rs1
4 files changed, 180 insertions, 364 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 888c70a394e..d3229fb3dd2 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -39,8 +39,13 @@ from Configuration import (
iteratorNativeType
)
-AUTOGENERATED_WARNING_COMMENT = \
- "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
+AUTOGENERATED_WARNING_COMMENT = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
+IGNORED_WARNING_LIST = ['non_camel_case_types', 'non_upper_case_globals', 'unused_imports',
+ 'unused_variables', 'unused_assignments', 'unused_mut',
+ 'clippy::approx_constant', 'clippy::let_unit_value', 'clippy::needless_return',
+ 'clippy::too_many_arguments', 'clippy::unnecessary_cast']
+IGNORED_WARNINGS = f"#![allow({','.join(IGNORED_WARNING_LIST)})]\n\n"
+
FINALIZE_HOOK_NAME = '_finalize'
TRACE_HOOK_NAME = '_trace'
CONSTRUCT_HOOK_NAME = '_constructor'
@@ -2160,25 +2165,10 @@ class CGImports(CGWrapper):
"""
Generates the appropriate import/use statements.
"""
- def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config,
- ignored_warnings=None):
+ def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config):
"""
Adds a set of imports.
"""
- if ignored_warnings is None:
- ignored_warnings = [
- 'non_camel_case_types',
- 'non_upper_case_globals',
- 'unused_imports',
- 'unused_variables',
- 'unused_assignments',
- 'unused_mut',
- 'clippy::approx_constant',
- 'clippy::let_unit_value',
- 'clippy::needless_return',
- 'clippy::too_many_arguments',
- 'clippy::unnecessary_cast',
- ]
def componentTypes(type):
if type.isType() and type.nullable():
@@ -2289,8 +2279,6 @@ class CGImports(CGWrapper):
extras += [getModuleFromObject(t) + '::' + getIdentifier(t).name]
statements = []
- if len(ignored_warnings) > 0:
- statements.append('#![allow(%s)]' % ','.join(ignored_warnings))
statements.extend('use %s;' % i for i in sorted(set(imports + extras)))
CGWrapper.__init__(self, child,
@@ -2377,7 +2365,7 @@ class CGDOMJSClass(CGThing):
def define(self):
parentName = self.descriptor.getParentName()
if not parentName:
- parentName = "crate::dom::bindings::reflector::Reflector"
+ parentName = "Reflector"
args = {
"domClass": DOMClass(self.descriptor),
@@ -2399,7 +2387,7 @@ class CGDOMJSClass(CGThing):
elif self.descriptor.weakReferenceable:
args["slots"] = "2"
return """\
-static CLASS_OPS: js::jsapi::JSClassOps = js::jsapi::JSClassOps {
+static CLASS_OPS: JSClassOps = JSClassOps {
addProperty: None,
delProperty: None,
enumerate: None,
@@ -2413,7 +2401,7 @@ static CLASS_OPS: js::jsapi::JSClassOps = js::jsapi::JSClassOps {
};
static Class: DOMJSClass = DOMJSClass {
- base: js::jsapi::JSClass {
+ base: JSClass {
name: %(name)s as *const u8 as *const libc::c_char,
flags: JSCLASS_IS_DOMJSCLASS | %(flags)s |
(((%(slots)s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
@@ -2442,7 +2430,7 @@ class CGAssertInheritance(CGThing):
if parent:
parentName = parent.identifier.name
else:
- parentName = "crate::dom::bindings::reflector::Reflector"
+ parentName = "Reflector"
selfName = self.descriptor.interface.identifier.name
@@ -2624,35 +2612,12 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
imports = [
'crate::dom',
- 'crate::dom::bindings::codegen::PrototypeList',
- 'crate::dom::bindings::conversions::ConversionResult',
- 'crate::dom::bindings::conversions::FromJSValConvertible',
- 'crate::dom::bindings::conversions::ToJSValConvertible',
- 'crate::dom::bindings::conversions::ConversionBehavior',
- 'crate::dom::bindings::conversions::StringificationBehavior',
- 'crate::dom::bindings::conversions::root_from_handlevalue',
+ 'crate::dom::bindings::import::base::*',
'crate::dom::bindings::conversions::windowproxy_from_handlevalue',
- 'std::ptr::NonNull',
- 'std::rc::Rc',
'crate::dom::bindings::record::Record',
- 'crate::dom::bindings::num::Finite',
- 'crate::dom::bindings::root::DomRoot',
- 'crate::dom::bindings::str::ByteString',
- 'crate::dom::bindings::str::DOMString',
- 'crate::dom::bindings::str::USVString',
- 'crate::dom::bindings::trace::RootedTraceableBox',
'crate::dom::types::*',
'crate::dom::windowproxy::WindowProxy',
- 'crate::script_runtime::JSContext as SafeJSContext',
- 'js::error::throw_type_error',
- 'js::rust::HandleValue',
- 'js::jsapi::Heap',
- 'js::jsapi::IsCallable',
- 'js::jsapi::JSContext',
- 'js::jsapi::JSObject',
- 'js::rust::MutableHandleValue',
- 'js::jsval::JSVal',
- 'js::typedarray'
+ 'js::typedarray',
]
# Now find all the things we'll need as arguments and return values because
@@ -2681,15 +2646,8 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
# Sort unionStructs by key, retrieve value
unionStructs = (i[1] for i in sorted(list(unionStructs.items()), key=operator.itemgetter(0)))
- return CGImports(CGList(unionStructs, "\n\n"),
- descriptors=[],
- callbacks=[],
- dictionaries=[],
- enums=[],
- typedefs=[],
- imports=imports,
- config=config,
- ignored_warnings=[])
+ return CGImports(CGList(unionStructs, "\n\n"), descriptors=[], callbacks=[], dictionaries=[], enums=[],
+ typedefs=[], imports=imports, config=config)
class Argument():
@@ -6344,307 +6302,6 @@ class CGWeakReferenceableTrait(CGThing):
return self.code
-def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries=None, enums=None, typedefs=None):
- if not callbacks:
- callbacks = []
- if not dictionaries:
- dictionaries = []
- if not enums:
- enums = []
- if not typedefs:
- typedefs = []
-
- return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [
- 'js',
- 'js::JSCLASS_GLOBAL_SLOT_COUNT',
- 'js::JSCLASS_IS_DOMJSCLASS',
- 'js::JSCLASS_IS_GLOBAL',
- 'js::JSCLASS_RESERVED_SLOTS_MASK',
- 'js::JS_CALLEE',
- 'js::error::throw_type_error',
- 'js::error::throw_internal_error',
- 'js::rust::wrappers::Call',
- 'js::jsapi::__BindgenBitfieldUnit',
- 'js::jsapi::CallArgs',
- 'js::jsapi::CurrentGlobalOrNull',
- 'js::rust::wrappers::GetPropertyKeys',
- 'js::rust::get_object_realm',
- 'js::rust::get_context_realm',
- 'js::jsapi::GCContext',
- 'js::jsapi::GetWellKnownSymbol',
- 'js::rust::Handle',
- 'js::jsapi::Handle as RawHandle',
- 'js::rust::HandleId',
- 'js::jsapi::HandleId as RawHandleId',
- 'js::rust::HandleObject',
- 'js::jsapi::HandleObject as RawHandleObject',
- 'js::rust::HandleValue',
- 'js::jsapi::HandleValue as RawHandleValue',
- 'js::jsapi::HandleValueArray',
- 'js::jsapi::Heap',
- 'js::rust::wrappers::RUST_INTERNED_STRING_TO_JSID',
- 'js::jsapi::IsCallable',
- 'js::jsapi::JSAutoRealm',
- 'js::jsapi::JSCLASS_FOREGROUND_FINALIZE',
- 'js::jsapi::JSCLASS_RESERVED_SLOTS_SHIFT',
- 'js::jsapi::JSClass',
- 'js::jsapi::JSContext',
- 'js::jsapi::JSFunctionSpec',
- 'js::jsapi::JSITER_HIDDEN',
- 'js::jsapi::JSITER_OWNONLY',
- 'js::jsapi::JSITER_SYMBOLS',
- 'js::jsapi::JSJitGetterCallArgs',
- 'js::jsapi::JSJitInfo',
- 'js::jsapi::JSJitInfo__bindgen_ty_1',
- 'js::jsapi::JSJitInfo__bindgen_ty_2',
- 'js::jsapi::JSJitInfo__bindgen_ty_3',
- 'js::jsapi::JSJitInfo_AliasSet',
- 'js::jsapi::JSJitInfo_ArgType',
- 'js::jsapi::JSJitInfo_OpType',
- 'js::jsapi::JSJitMethodCallArgs',
- 'js::jsapi::JSJitSetterCallArgs',
- 'js::jsapi::JSNative',
- 'js::jsapi::JSNativeWrapper',
- 'js::jsapi::JSObject',
- 'js::jsapi::JSPROP_ENUMERATE',
- 'js::jsapi::JSPROP_PERMANENT',
- 'js::jsapi::JSPROP_READONLY',
- 'js::jsapi::JSPropertySpec',
- 'js::jsapi::JSPropertySpec_Accessor',
- 'js::jsapi::JSPropertySpec_AccessorsOrValue',
- 'js::jsapi::JSPropertySpec_AccessorsOrValue_Accessors',
- 'js::jsapi::JSPropertySpec_Kind',
- 'js::jsapi::JSPropertySpec_Name',
- 'js::jsapi::JSPropertySpec_ValueWrapper',
- 'js::jsapi::JSPropertySpec_ValueWrapper_Type',
- 'js::jsapi::JSPropertySpec_ValueWrapper__bindgen_ty_1',
- 'js::jsapi::JSString',
- 'js::jsapi::JSTracer',
- 'js::jsapi::JSType',
- 'js::jsapi::JSTypedMethodJitInfo',
- 'js::jsapi::JSValueType',
- 'js::jsapi::JS_AtomizeAndPinString',
- 'js::rust::wrappers::JS_CallFunctionValue',
- 'js::rust::wrappers::JS_CopyOwnPropertiesAndPrivateFields',
- 'js::rust::wrappers::JS_DefineProperty',
- 'js::rust::wrappers::JS_DefinePropertyById2',
- 'js::jsapi::JS_ForwardGetPropertyTo',
- 'js::jsapi::GetRealmErrorPrototype',
- 'js::jsapi::GetRealmFunctionPrototype',
- 'js::jsapi::GetRealmIteratorPrototype',
- 'js::jsapi::GetRealmObjectPrototype',
- 'js::rust::wrappers::JS_GetProperty',
- 'js::jsapi::JS_GetPropertyById',
- 'js::jsapi::JS_GetPropertyDescriptorById',
- 'js::glue::JS_GetReservedSlot',
- 'js::jsapi::JS_HasProperty',
- 'js::jsapi::JS_HasPropertyById',
- 'js::rust::wrappers::JS_InitializePropertiesFromCompatibleNativeObject',
- 'js::jsapi::JS_NewPlainObject',
- 'js::jsapi::JS_NewObject',
- 'js::rust::RootedGuard',
- 'js::rust::wrappers::JS_NewObjectWithGivenProto',
- 'js::rust::wrappers::JS_NewObjectWithoutMetadata',
- 'js::rust::wrappers::ObjectIsDate',
- 'js::rust::wrappers::JS_SetImmutablePrototype',
- 'js::rust::wrappers::JS_SetProperty',
- 'js::rust::wrappers::JS_SetPrototype',
- 'js::jsapi::JS_SetReservedSlot',
- 'js::rust::wrappers::JS_WrapValue',
- 'js::rust::wrappers::JS_WrapObject',
- 'js::rust::MutableHandle',
- 'js::jsapi::MutableHandle as RawMutableHandle',
- 'js::rust::MutableHandleObject',
- 'js::jsapi::MutableHandleObject as RawMutableHandleObject',
- 'js::rust::MutableHandleValue',
- 'js::jsapi::MutableHandleValue as RawMutableHandleValue',
- 'js::jsapi::MutableHandleIdVector as RawMutableHandleIdVector',
- 'js::jsapi::ObjectOpResult',
- 'js::jsapi::PropertyDescriptor',
- 'js::jsapi::Rooted',
- 'js::jsapi::RootedId',
- 'js::jsapi::RootedObject',
- 'js::jsapi::RootedString',
- 'js::jsapi::SymbolCode',
- 'js::jsapi::jsid',
- 'js::jsval::JSVal',
- 'js::jsval::NullValue',
- 'js::jsval::ObjectValue',
- 'js::jsval::ObjectOrNullValue',
- 'js::jsval::PrivateValue',
- 'js::jsval::UndefinedValue',
- 'js::jsapi::UndefinedHandleValue',
- 'js::rust::wrappers::AppendToIdVector',
- 'js::glue::CallJitGetterOp',
- 'js::glue::CallJitMethodOp',
- 'js::glue::CallJitSetterOp',
- 'js::glue::CreateProxyHandler',
- 'js::glue::GetProxyReservedSlot',
- 'js::glue::SetProxyReservedSlot',
- 'js::rust::wrappers::NewProxyObject',
- 'js::glue::ProxyTraps',
- 'js::rust::wrappers::RUST_SYMBOL_TO_JSID',
- 'js::rust::wrappers::int_to_jsid',
- 'js::glue::UnwrapObjectDynamic',
- 'js::panic::maybe_resume_unwind',
- 'js::panic::wrap_panic',
- 'js::rust::GCMethods',
- 'js::rust::CustomAutoRooterGuard',
- 'js::rust::define_methods',
- 'js::rust::define_properties',
- 'js::rust::get_object_class',
- 'js::typedarray',
- 'js::typedarray::Int8Array',
- 'js::typedarray::Uint8Array',
- 'js::typedarray::Int16Array',
- 'js::typedarray::Uint16Array',
- 'js::typedarray::Int32Array',
- 'js::typedarray::Uint32Array',
- 'js::typedarray::Float32Array',
- 'js::typedarray::Float64Array',
- 'js::typedarray::ArrayBuffer',
- 'js::typedarray::ArrayBufferView',
- 'js::typedarray::Uint8ClampedArray',
- 'crate::dom',
- 'crate::dom::bindings',
- 'crate::dom::bindings::codegen::InterfaceObjectMap',
- 'crate::dom::bindings::constant::ConstantSpec',
- 'crate::dom::bindings::constant::ConstantVal',
- 'crate::dom::bindings::interface::ConstructorClassHook',
- 'crate::dom::bindings::interface::InterfaceConstructorBehavior',
- 'crate::dom::bindings::interface::NonCallbackInterfaceObjectClass',
- 'crate::dom::bindings::interface::ProtoOrIfaceIndex',
- 'crate::dom::bindings::interface::create_global_object',
- 'crate::dom::bindings::interface::create_callback_interface_object',
- 'crate::dom::bindings::interface::create_interface_prototype_object',
- 'crate::dom::bindings::interface::create_named_constructors',
- 'crate::dom::bindings::interface::create_noncallback_interface_object',
- 'crate::dom::bindings::interface::define_dom_interface',
- 'crate::dom::bindings::interface::define_guarded_constants',
- 'crate::dom::bindings::interface::define_guarded_methods',
- 'crate::dom::bindings::interface::define_guarded_properties',
- 'crate::dom::bindings::interface::is_exposed_in',
- 'crate::dom::bindings::interface::get_per_interface_object_handle',
- 'crate::dom::bindings::interface::get_desired_proto',
- 'crate::dom::bindings::htmlconstructor::pop_current_element_queue',
- 'crate::dom::bindings::htmlconstructor::push_new_element_queue',
- 'crate::dom::bindings::iterable::Iterable',
- 'crate::dom::bindings::iterable::IteratorType',
- 'crate::dom::bindings::like::Setlike',
- 'crate::dom::bindings::like::Maplike',
- 'crate::dom::bindings::namespace::NamespaceObjectClass',
- 'crate::dom::bindings::namespace::create_namespace_object',
- 'crate::dom::bindings::reflector::MutDomObject',
- 'crate::dom::bindings::reflector::DomObject',
- 'crate::dom::bindings::reflector::DomObjectWrap',
- 'crate::dom::bindings::reflector::DomObjectIteratorWrap',
- 'crate::dom::bindings::root::Dom',
- 'crate::dom::bindings::root::DomRoot',
- 'crate::dom::bindings::root::DomSlice',
- 'crate::dom::bindings::root::MaybeUnreflectedDom',
- 'crate::dom::bindings::root::OptionalHeapSetter',
- 'crate::dom::bindings::root::Root',
- 'crate::dom::bindings::utils::AsVoidPtr',
- 'crate::dom::bindings::utils::DOMClass',
- 'crate::dom::bindings::utils::DOMJSClass',
- 'crate::dom::bindings::utils::DOM_PROTO_UNFORGEABLE_HOLDER_SLOT',
- 'crate::dom::bindings::utils::JSCLASS_DOM_GLOBAL',
- 'crate::dom::bindings::utils::ProtoOrIfaceArray',
- 'crate::dom::bindings::utils::callargs_is_constructing',
- 'crate::dom::bindings::utils::enumerate_global',
- 'crate::dom::bindings::finalize::finalize_common',
- 'crate::dom::bindings::finalize::finalize_global',
- 'crate::dom::bindings::finalize::finalize_weak_referenceable',
- 'crate::dom::bindings::utils::generic_getter',
- 'crate::dom::bindings::utils::generic_lenient_getter',
- 'crate::dom::bindings::utils::generic_lenient_setter',
- 'crate::dom::bindings::utils::generic_method',
- 'crate::dom::bindings::utils::generic_setter',
- 'crate::dom::bindings::utils::get_array_index_from_id',
- 'crate::dom::bindings::utils::get_dictionary_property',
- 'crate::dom::bindings::utils::get_property_on_prototype',
- 'crate::dom::bindings::utils::get_proto_or_iface_array',
- 'crate::dom::bindings::utils::has_property_on_prototype',
- 'crate::dom::bindings::utils::is_platform_object_dynamic',
- 'crate::dom::bindings::utils::is_platform_object_static',
- 'crate::dom::bindings::utils::resolve_global',
- 'crate::dom::bindings::utils::set_dictionary_property',
- 'crate::dom::bindings::utils::trace_global',
- 'crate::dom::bindings::trace::JSTraceable',
- 'crate::dom::bindings::trace::RootedTraceableBox',
- 'crate::dom::bindings::callback::CallSetup',
- 'crate::dom::bindings::callback::CallbackContainer',
- 'crate::dom::bindings::callback::CallbackInterface',
- 'crate::dom::bindings::callback::CallbackFunction',
- 'crate::dom::bindings::callback::CallbackObject',
- 'crate::dom::bindings::callback::ExceptionHandling',
- 'crate::dom::bindings::callback::wrap_call_this_object',
- 'crate::dom::bindings::conversions::ConversionBehavior',
- 'crate::dom::bindings::conversions::ConversionResult',
- 'crate::dom::bindings::conversions::DOM_OBJECT_SLOT',
- 'crate::dom::bindings::conversions::FromJSValConvertible',
- 'crate::dom::bindings::conversions::IDLInterface',
- 'crate::dom::bindings::conversions::StringificationBehavior',
- 'crate::dom::bindings::conversions::ToJSValConvertible',
- 'crate::dom::bindings::conversions::is_array_like',
- 'crate::dom::bindings::conversions::native_from_handlevalue',
- 'crate::dom::bindings::conversions::native_from_object',
- 'crate::dom::bindings::conversions::native_from_object_static',
- 'crate::dom::bindings::conversions::private_from_object',
- 'crate::dom::bindings::conversions::root_from_handleobject',
- 'crate::dom::bindings::conversions::root_from_handlevalue',
- 'crate::dom::bindings::conversions::root_from_object',
- 'crate::dom::bindings::conversions::jsid_to_string',
- 'crate::dom::bindings::codegen::PrototypeList',
- 'crate::dom::bindings::codegen::RegisterBindings',
- 'crate::dom::bindings::codegen::UnionTypes',
- 'crate::dom::bindings::error::Error',
- 'crate::dom::bindings::error::ErrorResult',
- 'crate::dom::bindings::error::Fallible',
- 'crate::dom::bindings::error::Error::JSFailed',
- 'crate::dom::bindings::error::throw_dom_exception',
- 'crate::dom::bindings::error::throw_constructor_without_new',
- 'crate::dom::bindings::guard::Condition',
- 'crate::dom::bindings::guard::Guard',
- 'crate::dom::bindings::inheritance::Castable',
- 'crate::dom::bindings::proxyhandler',
- 'crate::dom::bindings::proxyhandler::ensure_expando_object',
- 'crate::dom::bindings::proxyhandler::set_property_descriptor',
- 'crate::dom::bindings::proxyhandler::get_expando_object',
- 'crate::dom::bindings::record::Record',
- 'std::ptr::NonNull',
- 'crate::dom::bindings::num::Finite',
- 'crate::dom::bindings::str::ByteString',
- 'crate::dom::bindings::str::DOMString',
- 'crate::dom::bindings::str::USVString',
- 'crate::dom::bindings::weakref::DOM_WEAK_SLOT',
- 'crate::dom::bindings::weakref::WeakBox',
- 'crate::dom::bindings::weakref::WeakReferenceable',
- 'crate::dom::windowproxy::WindowProxy',
- 'crate::dom::globalscope::GlobalScope',
- 'crate::mem::malloc_size_of_including_raw_self',
- 'crate::realms::InRealm',
- 'crate::realms::AlreadyInRealm',
- 'crate::script_runtime::JSContext as SafeJSContext',
- 'libc',
- 'servo_config::pref',
- 'servo_config::prefs',
- 'std::borrow::ToOwned',
- 'std::cmp',
- 'std::mem',
- 'std::num',
- 'std::os',
- 'std::panic',
- 'std::ptr',
- 'std::str',
- 'std::rc',
- 'std::rc::Rc',
- 'std::default::Default',
- 'std::ffi::CString',
- 'std::ops::Deref',
- ], config)
-
-
class CGDescriptor(CGThing):
def __init__(self, descriptor, config, soleDescriptor):
CGThing.__init__(self)
@@ -6828,7 +6485,16 @@ class CGDescriptor(CGThing):
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties, haveUnscopables,
haveLegacyWindowAliases))
- cgThings = generate_imports(config, CGList(cgThings, '\n'), [descriptor])
+ cgThings = CGList(cgThings, '\n')
+
+ # Add imports
+ # These are inside the generated module
+ cgThings = CGImports(cgThings, descriptors=[descriptor], callbacks=[],
+ dictionaries=[], enums=[], typedefs=[], imports=[
+ 'crate::dom',
+ 'crate::dom::bindings::import::module::*',
+ ], config=config)
+
cgThings = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
cgThings, public=True),
post='\n')
@@ -7275,11 +6941,13 @@ class CGBindingRoot(CGThing):
curr = CGWrapper(CGList(cgthings, "\n\n"), post="\n\n")
# Add imports
- curr = generate_imports(config, curr, callbackDescriptors, mainCallbacks,
- dictionaries, enums, typedefs)
+ # These are the global imports (outside of the generated module)
+ curr = CGImports(curr, descriptors=callbackDescriptors, callbacks=mainCallbacks,
+ dictionaries=dictionaries, enums=enums, typedefs=typedefs,
+ imports=['crate::dom::bindings::import::base::*'], config=config)
# Add the auto-generated comment.
- curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
+ curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT + IGNORED_WARNINGS)
# Store the final result.
self.root = curr
@@ -8146,7 +7814,7 @@ class GlobalGenRoots():
return CGImports(code, descriptors=[], callbacks=[], dictionaries=[], enums=[], typedefs=[], imports=[
'crate::dom::bindings::codegen::Bindings',
- ], config=config, ignored_warnings=[])
+ ], config=config)
@staticmethod
def InterfaceTypes(config):
diff --git a/components/script/dom/bindings/import.rs b/components/script/dom/bindings/import.rs
new file mode 100644
index 00000000000..34ac97fd31a
--- /dev/null
+++ b/components/script/dom/bindings/import.rs
@@ -0,0 +1,146 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+pub mod base {
+ pub use std::ptr;
+ pub use std::rc::Rc;
+
+ pub use js::error::throw_type_error;
+ pub use js::jsapi::{
+ CurrentGlobalOrNull, HandleValue as RawHandleValue, HandleValueArray, Heap, IsCallable,
+ JSContext, JSObject, JS_NewObject,
+ };
+ pub use js::jsval::{JSVal, NullValue, ObjectOrNullValue, ObjectValue, UndefinedValue};
+ pub use js::panic::maybe_resume_unwind;
+ pub use js::rust::wrappers::{JS_CallFunctionValue, JS_WrapValue};
+ pub use js::rust::{HandleObject, HandleValue, MutableHandleObject, MutableHandleValue};
+
+ pub use crate::dom::bindings::callback::{
+ wrap_call_this_object, CallSetup, CallbackContainer, CallbackFunction, CallbackInterface,
+ CallbackObject, ExceptionHandling,
+ };
+ pub use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
+ ChannelCountMode, ChannelCountModeValues, ChannelInterpretation,
+ ChannelInterpretationValues,
+ };
+ pub use crate::dom::bindings::codegen::UnionTypes;
+ pub use crate::dom::bindings::conversions::{
+ root_from_handlevalue, ConversionBehavior, ConversionResult, FromJSValConvertible,
+ StringificationBehavior, ToJSValConvertible,
+ };
+ pub use crate::dom::bindings::error::Error::JSFailed;
+ pub use crate::dom::bindings::error::{throw_dom_exception, Fallible};
+ pub use crate::dom::bindings::num::Finite;
+ pub use crate::dom::bindings::reflector::DomObject;
+ pub use crate::dom::bindings::root::DomRoot;
+ pub use crate::dom::bindings::str::{ByteString, DOMString, USVString};
+ pub use crate::dom::bindings::trace::RootedTraceableBox;
+ pub use crate::dom::bindings::utils::{get_dictionary_property, set_dictionary_property};
+ pub use crate::dom::globalscope::GlobalScope;
+ pub use crate::script_runtime::JSContext as SafeJSContext;
+}
+
+pub mod module {
+ pub use std::cmp;
+ pub use std::ffi::CString;
+ pub use std::ptr::NonNull;
+
+ pub use js::glue::{
+ CreateProxyHandler, GetProxyReservedSlot, JS_GetReservedSlot, ProxyTraps,
+ SetProxyReservedSlot,
+ };
+ pub use js::jsapi::{
+ JSJitInfo_OpType, JSJitInfo__bindgen_ty_1, JSJitInfo__bindgen_ty_2,
+ JSJitInfo__bindgen_ty_3, JSJitMethodCallArgs, JSJitSetterCallArgs, JSNativeWrapper,
+ JSPropertySpec, JSPropertySpec_Accessor, JSPropertySpec_AccessorsOrValue,
+ JSPropertySpec_AccessorsOrValue_Accessors, JSPropertySpec_Kind, JSPropertySpec_Name,
+ JSPropertySpec_ValueWrapper, JSPropertySpec_ValueWrapper_Type,
+ JSPropertySpec_ValueWrapper__bindgen_ty_1, JSTracer, JSTypedMethodJitInfo, JSValueType,
+ JS_AtomizeAndPinString, JS_ForwardGetPropertyTo, JS_GetPropertyDescriptorById,
+ JS_HasPropertyById, JS_NewPlainObject, JS_SetReservedSlot,
+ MutableHandle as RawMutableHandle, MutableHandleIdVector as RawMutableHandleIdVector,
+ MutableHandleObject as RawMutableHandleObject, MutableHandleValue as RawMutableHandleValue,
+ ObjectOpResult, PropertyDescriptor, SymbolCode, UndefinedHandleValue,
+ __BindgenBitfieldUnit, jsid, CallArgs, GCContext, GetRealmErrorPrototype,
+ GetRealmFunctionPrototype, GetRealmIteratorPrototype, GetRealmObjectPrototype,
+ GetWellKnownSymbol, Handle as RawHandle, HandleId as RawHandleId,
+ HandleObject as RawHandleObject, JSAutoRealm, JSClass, JSClassOps, JSFunctionSpec,
+ JSJitGetterCallArgs, JSJitInfo, JSJitInfo_AliasSet, JSJitInfo_ArgType,
+ JSCLASS_FOREGROUND_FINALIZE, JSCLASS_RESERVED_SLOTS_SHIFT, JSITER_HIDDEN, JSITER_OWNONLY,
+ JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY,
+ };
+ pub use js::jsval::PrivateValue;
+ pub use js::panic::wrap_panic;
+ pub use js::rust::wrappers::{
+ int_to_jsid, AppendToIdVector, Call, GetPropertyKeys, JS_CopyOwnPropertiesAndPrivateFields,
+ JS_DefineProperty, JS_DefinePropertyById2, JS_GetProperty,
+ JS_InitializePropertiesFromCompatibleNativeObject, JS_NewObjectWithGivenProto,
+ JS_NewObjectWithoutMetadata, JS_SetImmutablePrototype, JS_SetProperty, JS_SetPrototype,
+ JS_WrapObject, NewProxyObject, RUST_INTERNED_STRING_TO_JSID, RUST_SYMBOL_TO_JSID,
+ };
+ pub use js::rust::{
+ get_context_realm, get_object_class, get_object_realm, CustomAutoRooterGuard, GCMethods,
+ Handle, MutableHandle, RootedGuard,
+ };
+ pub use js::typedarray::{
+ ArrayBuffer, ArrayBufferView, Float32Array, Float64Array, Uint8Array, Uint8ClampedArray,
+ };
+ pub use js::{
+ jsapi, typedarray, JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL,
+ JSCLASS_RESERVED_SLOTS_MASK, JS_CALLEE,
+ };
+ pub use servo_config::pref;
+
+ pub use super::base::*;
+ pub use crate::dom::bindings::codegen::Bindings::AnalyserNodeBinding::AnalyserOptions;
+ pub use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
+ AudioNode_Binding, ChannelCountMode, ChannelCountModeValues, ChannelInterpretation,
+ ChannelInterpretationValues,
+ };
+ pub use crate::dom::bindings::codegen::Bindings::EventTargetBinding::EventTarget_Binding;
+ pub use crate::dom::bindings::codegen::{InterfaceObjectMap, PrototypeList, RegisterBindings};
+ pub use crate::dom::bindings::constant::{ConstantSpec, ConstantVal};
+ pub use crate::dom::bindings::conversions::{
+ is_array_like, jsid_to_string, native_from_handlevalue, native_from_object_static,
+ IDLInterface, StringificationBehavior, ToJSValConvertible, DOM_OBJECT_SLOT,
+ };
+ pub use crate::dom::bindings::error::{throw_constructor_without_new, Error, ErrorResult};
+ pub use crate::dom::bindings::finalize::{
+ finalize_common, finalize_global, finalize_weak_referenceable,
+ };
+ pub use crate::dom::bindings::guard::{Condition, Guard};
+ pub use crate::dom::bindings::htmlconstructor::{
+ pop_current_element_queue, push_new_element_queue,
+ };
+ pub use crate::dom::bindings::inheritance::Castable;
+ pub use crate::dom::bindings::interface::{
+ create_callback_interface_object, create_global_object, create_interface_prototype_object,
+ create_named_constructors, create_noncallback_interface_object, define_dom_interface,
+ define_guarded_methods, define_guarded_properties, get_desired_proto,
+ get_per_interface_object_handle, is_exposed_in, ConstructorClassHook,
+ InterfaceConstructorBehavior, NonCallbackInterfaceObjectClass, ProtoOrIfaceIndex,
+ };
+ pub use crate::dom::bindings::iterable::{Iterable, IteratorType};
+ pub use crate::dom::bindings::like::{Maplike, Setlike};
+ pub use crate::dom::bindings::namespace::{create_namespace_object, NamespaceObjectClass};
+ pub use crate::dom::bindings::proxyhandler;
+ pub use crate::dom::bindings::proxyhandler::{
+ ensure_expando_object, get_expando_object, set_property_descriptor,
+ };
+ pub use crate::dom::bindings::record::Record;
+ pub use crate::dom::bindings::reflector::{DomObjectIteratorWrap, DomObjectWrap, Reflector};
+ pub use crate::dom::bindings::root::{Dom, DomSlice, MaybeUnreflectedDom, Root};
+ pub use crate::dom::bindings::trace::JSTraceable;
+ pub use crate::dom::bindings::utils::{
+ callargs_is_constructing, enumerate_global, generic_getter, generic_lenient_getter,
+ generic_lenient_setter, generic_method, generic_setter, get_array_index_from_id,
+ get_property_on_prototype, has_property_on_prototype, resolve_global, trace_global,
+ AsVoidPtr, DOMClass, DOMJSClass, ProtoOrIfaceArray, DOM_PROTO_UNFORGEABLE_HOLDER_SLOT,
+ JSCLASS_DOM_GLOBAL,
+ };
+ pub use crate::dom::bindings::weakref::{WeakReferenceable, DOM_WEAK_SLOT};
+ pub use crate::dom::types::{AnalyserNode, AudioNode, BaseAudioContext, EventTarget};
+ pub use crate::mem::malloc_size_of_including_raw_self;
+ pub use crate::realms::{AlreadyInRealm, InRealm};
+}
diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs
index 82608367aef..a2713e1c95f 100644
--- a/components/script/dom/bindings/mod.rs
+++ b/components/script/dom/bindings/mod.rs
@@ -143,6 +143,7 @@ pub mod error;
pub mod finalize;
pub mod guard;
pub mod htmlconstructor;
+pub mod import;
pub mod inheritance;
pub mod interface;
pub mod iterable;
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 198468bb007..14c4675af3f 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -260,6 +260,7 @@ pub unsafe fn find_enum_value<'a, T>(
/// Returns wether `obj` is a platform object using dynamic unwrap
/// <https://heycam.github.io/webidl/#dfn-platform-object>
+#[allow(dead_code)]
pub fn is_platform_object_dynamic(obj: *mut JSObject, cx: *mut JSContext) -> bool {
is_platform_object(obj, &|o| unsafe {
UnwrapObjectDynamic(o, cx, /* stopAtWindowProxy = */ false)