Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specialized constructors for singly-exposed DOM types #14160

Closed
wants to merge 1 commit into from

Conversation

@ajnirp
Copy link
Contributor

ajnirp commented Nov 10, 2016


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14071 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because these are codegen changes and the generated code builds successfully

This change is Reviewable

@highfive
Copy link

highfive commented Nov 10, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/comment.rs, components/script/dom/webglcontextevent.rs, components/script/dom/dommatrixreadonly.rs, components/script/dom/dommatrix.rs, components/script/dom/document.rs, components/script/dom/documentfragment.rs, components/script/dom/text.rs, components/script/dom/keyboardevent.rs, components/script/dom/range.rs, components/script/dom/focusevent.rs, components/script/dom/extendablemessageevent.rs, components/script/dom/domparser.rs, components/script/dom/htmlimageelement.rs, components/script/dom/mouseevent.rs, components/script/dom/transitionevent.rs, components/script/dom/extendableevent.rs, components/script/dom/uievent.rs
  • @fitzgen: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/comment.rs, components/script/dom/webglcontextevent.rs, components/script/dom/dommatrixreadonly.rs, components/script/dom/dommatrix.rs, components/script/dom/document.rs, components/script/dom/documentfragment.rs, components/script/dom/text.rs, components/script/dom/keyboardevent.rs, components/script/dom/range.rs, components/script/dom/focusevent.rs, components/script/dom/extendablemessageevent.rs, components/script/dom/domparser.rs, components/script/dom/htmlimageelement.rs, components/script/dom/mouseevent.rs, components/script/dom/transitionevent.rs, components/script/dom/extendableevent.rs, components/script/dom/uievent.rs
  • @emilio: components/script/dom/webglcontextevent.rs
@highfive
Copy link

highfive commented Nov 10, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
Copy link
Member

nox left a comment

Thanks for your contribution!

globalName = list(self.exposureSet)[0]
downcast = """let global = global.downcast::<dom::{}::{}>().unwrap();\n"""
downcast = downcast.format(globalName.lower(),
globalName[0].upper() + globalName[1:])

This comment has been minimized.

@nox

nox Nov 10, 2016

Member

Could you explain what these two lines are supposed to do? Also you may want to look at MakeNativeName in Configuration.py.

This comment has been minimized.

@ajnirp

ajnirp Nov 11, 2016

Author Contributor

This is for the case when a DOM type is exposed to exactly one global. In that case, we downcast global from GlobalScope to that particular struct.

Thank you for pointing out MakeNativeName! I have fixed it.

@@ -3170,7 +3170,7 @@ def __init__(self, errorResult, arguments, argsPre, returnType,

if isFallible:
if static:
glob = "&global"
glob = "global.upcast::<GlobalScope>()"

This comment has been minimized.

@nox

nox Nov 10, 2016

Member

Why is this needed?

This comment has been minimized.

@ajnirp

ajnirp Nov 11, 2016

Author Contributor

It's needed to prevent compile errors in the call to throw_dom_exception that gets generated from CGCallGenerator::__init__(). Without this change, we end up passing a reference to a GlobalScope-derived struct as the 2nd parameter to throw_dom_exception whereas it expects to see a &GlobalScope.

@@ -82,6 +83,8 @@ impl WebGLContextEvent {

let cancelable = EventCancelable::from(init.parent.cancelable);

let global = window.upcast::<GlobalScope>();

This comment has been minimized.

@nox

nox Nov 10, 2016

Member

WebGLContextEvent::new should probably be made to take a &Window too.

This comment has been minimized.

@ajnirp

ajnirp Nov 11, 2016

Author Contributor

Done!

type_: DOMString,
init: &ExtendableEventBinding::ExtendableEventInit) -> Fallible<Root<ExtendableEvent>> {
let global = worker.upcast::<GlobalScope>();

This comment has been minimized.

@nox

nox Nov 10, 2016

Member

ExtendableEvent::new should take a &Window.

This comment has been minimized.

@ajnirp

ajnirp Nov 11, 2016

Author Contributor

I think this should be &ServiceWorkerGlobalScope, based on ExtendableEvent.webidl Updated!

type_: DOMString,
init: &ExtendableMessageEventBinding::ExtendableMessageEventInit)
-> Fallible<Root<ExtendableMessageEvent>> {
let global = worker.upcast::<GlobalScope>();

This comment has been minimized.

@nox

nox Nov 10, 2016

Member

ExtendableMessageEvent::new should take a &Window.

This comment has been minimized.

@ajnirp

ajnirp Nov 11, 2016

Author Contributor

Likewise, I think this should be &ServiceWorkerGlobalScope as well. Updated!

This comment has been minimized.

@nox

nox Nov 11, 2016

Member

Oh right! :)

@@ -40,12 +42,14 @@ impl DOMMatrixReadOnly {
}

// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly
pub fn Constructor(global: &GlobalScope) -> Fallible<Root<Self>> {
pub fn Constructor(window: &Window) -> Fallible<Root<Self>> {

This comment has been minimized.

@nox

nox Nov 10, 2016

Member

DOMMatrix and friends are supposed to be Exposed=(Window,Worker).

This comment has been minimized.

@ajnirp

ajnirp Nov 11, 2016

Author Contributor

To address this, I uncommented the Exposed=(Window,Worker) lines in the WebIDLs for DOMMatrix{ReadOnly} and removed the up/down casting in their .rs files. Is this okay?

@nox nox assigned nox and unassigned asajeffrey Nov 10, 2016
@ajnirp ajnirp force-pushed the ajnirp:14071-specialized-constructors branch from 1b0a6c7 to 1736be7 Nov 11, 2016
preamble = """let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n"""
if len(self.exposureSet) == 1:
globalName = list(self.exposureSet)[0]
downcast = """let global = global.downcast::<dom::{}::{}>().unwrap();\n"""

This comment has been minimized.

@nox

nox Nov 11, 2016

Member

I think you can just do:

let downcast = "global.downcast::<%s>().unwrap();" % descriptor.path
type_: DOMString,
init: &ExtendableMessageEventBinding::ExtendableMessageEventInit)
-> Fallible<Root<ExtendableMessageEvent>> {
let global = worker.upcast::<GlobalScope>();

This comment has been minimized.

@nox

nox Nov 11, 2016

Member

Oh right! :)

Constructor(sequence<unrestricted double> numberSequence)
// Exposed=(Window,Worker)
Constructor(sequence<unrestricted double> numberSequence),
Exposed=(Window,Worker)

This comment has been minimized.

@nox

nox Nov 11, 2016

Member

Could you do that in a first separate commit?

@bors-servo
Copy link
Contributor

bors-servo commented Nov 14, 2016

The latest upstream changes (presumably #14201) made this pull request unmergeable. Please resolve the merge conflicts.

@ajnirp ajnirp force-pushed the ajnirp:14071-specialized-constructors branch from 1736be7 to f0c0d6a Nov 23, 2016
@ajnirp ajnirp force-pushed the ajnirp:14071-specialized-constructors branch from f0c0d6a to c1a6e02 Nov 24, 2016
@nox
Copy link
Member

nox commented Nov 27, 2016

Carried in #14376, thanks for your contribution!

@nox nox closed this Nov 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.