diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-06-03 16:59:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-03 16:59:32 -0400 |
commit | 7758d4ff620930464ec1c500fd018eac15e37af6 (patch) | |
tree | 39226d1976e047b9f2e88cae099c903601382027 /components/script/dom/bindings/codegen | |
parent | d6751d3068447458b12bbe17dd70737eec241d97 (diff) | |
parent | 2da07ed164b71c679813b4c319a6e069a2910b25 (diff) | |
download | servo-7758d4ff620930464ec1c500fd018eac15e37af6.tar.gz servo-7758d4ff620930464ec1c500fd018eac15e37af6.zip |
Auto merge of #25432 - warren-fisher:HTMLConstructor, r=jdm
Extract some of CGClassConstructHook to utils.rs
<!-- Please describe your changes on the following line: -->
Moving some of the functionality from the massive tripled quoted string in CGClassConstructHook in `components/script/dom/bindings/codegen/CodegenRust.py` to `components/script/dom/bindings/utils.rs`. Must be made unsafe because of UnwrapObjectDynamic and other functions. Added imports as necessary as well, as well as cleaning up using test-tidy.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #25395 (GitHub issue number if applicable)
<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because the issue says so
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 76 |
1 files changed, 6 insertions, 70 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 8c7eb3e7400..b486806e562 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5761,75 +5761,12 @@ let global = DomRoot::downcast::<dom::types::%s>(global).unwrap(); if self.constructor.isHTMLConstructor(): signatures = self.constructor.signatures() assert len(signatures) == 1 - constructorCall = CGGeneric("""\ -// Step 2 https://html.spec.whatwg.org/multipage/#htmlconstructor -// The custom element definition cannot use an element interface as its constructor - -// The new_target might be a cross-realm wrapper. Get the underlying object -// so we can do the spec's object-identity checks. -rooted!(in(*cx) let new_target = UnwrapObjectDynamic(args.new_target().to_object(), *cx, 1)); -if new_target.is_null() { - throw_dom_exception(cx, global.upcast::<GlobalScope>(), Error::Type("new.target is null".to_owned())); - return false; -} - -if args.callee() == new_target.get() { - throw_dom_exception(cx, global.upcast::<GlobalScope>(), - Error::Type("new.target must not be the active function object".to_owned())); - return false; -} - -// Step 6 -rooted!(in(*cx) let mut prototype = ptr::null_mut::<JSObject>()); -{ - rooted!(in(*cx) let mut proto_val = UndefinedValue()); - let _ac = JSAutoRealm::new(*cx, new_target.get()); - if !JS_GetProperty(*cx, new_target.handle(), b"prototype\\0".as_ptr() as *const _, proto_val.handle_mut()) { - return false; - } - - if !proto_val.is_object() { - // Step 7 of https://html.spec.whatwg.org/multipage/#htmlconstructor. - // This fallback behavior is designed to match analogous behavior for the - // JavaScript built-ins. So we enter the realm of our underlying - // newTarget object and fall back to the prototype object from that global. - // XXX The spec says to use GetFunctionRealm(), which is not actually - // the same thing as what we have here (e.g. in the case of scripted callable proxies - // whose target is not same-realm with the proxy, or bound functions, etc). - // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658 - - rooted!(in(*cx) let global_object = CurrentGlobalOrNull(*cx)); - GetProtoObject(cx, global_object.handle(), prototype.handle_mut()); - } else { - // Step 6 - prototype.set(proto_val.to_object()); - }; -} - -// Wrap prototype in this context since it is from the newTarget realm -if !JS_WrapObject(*cx, prototype.handle_mut()) { - return false; -} - -let result: Result<DomRoot<%s>, Error> = html_constructor(&global, &args); -let result = match result { - Ok(result) => result, - Err(e) => { - throw_dom_exception(cx, global.upcast::<GlobalScope>(), e); - return false; - }, -}; - -rooted!(in(*cx) let mut element = result.reflector().get_jsobject().get()); -if !JS_WrapObject(*cx, element.handle_mut()) { - return false; -} - -JS_SetPrototype(*cx, element.handle(), prototype.handle()); - -(result).to_jsval(*cx, MutableHandleValue::from_raw(args.rval())); -return true; -""" % self.descriptor.name) + constructorCall = CGGeneric("""dom::bindings::htmlconstructor::call_html_constructor::<dom::types::%s>( + cx, + &args, + &*global, + GetProtoObject, + )""" % self.descriptor.name) else: name = self.constructor.identifier.name nativeName = MakeNativeName(self.descriptor.binaryNameFor(name)) @@ -6145,7 +6082,6 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'crate::dom::bindings::interface::define_guarded_constants', 'crate::dom::bindings::interface::define_guarded_methods', 'crate::dom::bindings::interface::define_guarded_properties', - 'crate::dom::bindings::htmlconstructor::html_constructor', 'crate::dom::bindings::interface::is_exposed_in', 'crate::dom::bindings::htmlconstructor::pop_current_element_queue', 'crate::dom::bindings::htmlconstructor::push_new_element_queue', |