aboutsummaryrefslogtreecommitdiffstats
path: root/components/script_bindings
diff options
context:
space:
mode:
Diffstat (limited to 'components/script_bindings')
-rw-r--r--components/script_bindings/codegen/Bindings.conf2
-rw-r--r--components/script_bindings/codegen/CodegenRust.py97
-rw-r--r--components/script_bindings/import.rs6
-rw-r--r--components/script_bindings/interfaces.rs19
-rw-r--r--components/script_bindings/webidls/Document.webidl1
-rw-r--r--components/script_bindings/webidls/Element.webidl8
-rw-r--r--components/script_bindings/webidls/EventHandler.webidl30
-rw-r--r--components/script_bindings/webidls/HTMLElement.webidl1
8 files changed, 49 insertions, 115 deletions
diff --git a/components/script_bindings/codegen/Bindings.conf b/components/script_bindings/codegen/Bindings.conf
index 2a9874a386f..875a9498078 100644
--- a/components/script_bindings/codegen/Bindings.conf
+++ b/components/script_bindings/codegen/Bindings.conf
@@ -538,7 +538,7 @@ DOMInterfaces = {
'Promise': {
'spiderMonkeyInterface': True,
- 'additionalTraits': ["crate::interfaces::PromiseHelpers<Self>", "js::conversions::FromJSValConvertibleRc"]
+ 'additionalTraits': ["js::conversions::FromJSValConvertibleRc"]
},
'Range': {
diff --git a/components/script_bindings/codegen/CodegenRust.py b/components/script_bindings/codegen/CodegenRust.py
index 48f024be70f..458aa7508b0 100644
--- a/components/script_bindings/codegen/CodegenRust.py
+++ b/components/script_bindings/codegen/CodegenRust.py
@@ -742,6 +742,19 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
"}")
return templateBody
+ # A helper function for types that implement FromJSValConvertible trait
+ def fromJSValTemplate(config, errorHandler, exceptionCode):
+ return f"""match FromJSValConvertible::from_jsval(*cx, ${{val}}, {config}) {{
+ Ok(ConversionResult::Success(value)) => value,
+ Ok(ConversionResult::Failure(error)) => {{
+ {errorHandler}
+ }}
+ _ => {{
+ {exceptionCode}
+ }},
+}}
+"""
+
assert not (isEnforceRange and isClamp) # These are mutually exclusive
if type.isSequence() or type.isRecord():
@@ -755,13 +768,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=" >")
- templateBody = (f"match FromJSValConvertible::from_jsval(*cx, ${{val}}, {config}) {{\n"
- " Ok(ConversionResult::Success(value)) => value,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }},\n"
- "}")
+ templateBody = fromJSValTemplate(config, failOrPropagate, exceptionCode)
return handleOptional(templateBody, declType, handleDefault("None"))
@@ -770,13 +777,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=" >")
- templateBody = ("match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
- " Ok(ConversionResult::Success(value)) => value,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }},\n"
- "}")
+ templateBody = fromJSValTemplate("()", failOrPropagate, exceptionCode)
dictionaries = [
memberType
@@ -836,21 +837,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
# once again be providing a Promise to signal completion of an
# operation, which would then not be exposed to anyone other than
# our own implementation code.
- templateBody = fill(
- """
- { // Scope for our JSAutoRealm.
-
- rooted!(in(*cx) let globalObj = CurrentGlobalOrNull(*cx));
- let promiseGlobal = D::GlobalScope::from_object_maybe_wrapped(globalObj.handle().get(), *cx);
-
- rooted!(in(*cx) let mut valueToResolve = $${val}.get());
- if !JS_WrapValue(*cx, valueToResolve.handle_mut()) {
- $*{exceptionCode}
- }
- D::Promise::new_resolved(&promiseGlobal, cx, valueToResolve.handle())
- }
- """,
- exceptionCode=exceptionCode)
+ templateBody = fromJSValTemplate("()", failOrPropagate, exceptionCode)
if isArgument:
declType = CGGeneric("&D::Promise")
@@ -960,14 +947,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.isDOMString():
nullBehavior = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs)
- conversionCode = (
- f"match FromJSValConvertible::from_jsval(*cx, ${{val}}, {nullBehavior}) {{\n"
- " Ok(ConversionResult::Success(strval)) => strval,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }},\n"
- "}")
+ conversionCode = fromJSValTemplate(nullBehavior, failOrPropagate, exceptionCode)
if defaultValue is None:
default = None
@@ -989,14 +969,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.isUSVString():
assert not isEnforceRange and not isClamp
- conversionCode = (
- "match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
- " Ok(ConversionResult::Success(strval)) => strval,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }},\n"
- "}")
+ conversionCode = fromJSValTemplate("()", failOrPropagate, exceptionCode)
if defaultValue is None:
default = None
@@ -1018,14 +991,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.isByteString():
assert not isEnforceRange and not isClamp
- conversionCode = (
- "match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
- " Ok(ConversionResult::Success(strval)) => strval,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }},\n"
- "}")
+ conversionCode = fromJSValTemplate("()", failOrPropagate, exceptionCode)
if defaultValue is None:
default = None
@@ -1056,12 +1022,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
else:
handleInvalidEnumValueCode = "return true;"
- template = (
- "match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {"
- f" Err(_) => {{ {exceptionCode} }},\n"
- " Ok(ConversionResult::Success(v)) => v,\n"
- f" Ok(ConversionResult::Failure(error)) => {{ {handleInvalidEnumValueCode} }},\n"
- "}")
+ template = fromJSValTemplate("()", handleInvalidEnumValueCode, exceptionCode)
if defaultValue is not None:
assert defaultValue.type.tag() == IDLType.Tags.domstring
@@ -1192,14 +1153,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type_needs_tracing(type):
declType = CGTemplatedType("RootedTraceableBox", declType)
- template = (
- "match FromJSValConvertible::from_jsval(*cx, ${val}, ()) {\n"
- " Ok(ConversionResult::Success(dictionary)) => dictionary,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }},\n"
- "}")
+ template = fromJSValTemplate("()", failOrPropagate, exceptionCode)
return handleOptional(template, declType, handleDefault(empty))
@@ -1220,14 +1174,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=">")
- template = (
- f"match FromJSValConvertible::from_jsval(*cx, ${{val}}, {conversionBehavior}) {{\n"
- " Ok(ConversionResult::Success(v)) => v,\n"
- " Ok(ConversionResult::Failure(error)) => {\n"
- f"{indent(failOrPropagate, 8)}\n"
- " }\n"
- f" _ => {{ {exceptionCode} }}\n"
- "}")
+ template = fromJSValTemplate(conversionBehavior, failOrPropagate, exceptionCode)
if defaultValue is not None:
if isinstance(defaultValue, IDLNullValue):
diff --git a/components/script_bindings/import.rs b/components/script_bindings/import.rs
index 16cc92f07bf..25bd6c38669 100644
--- a/components/script_bindings/import.rs
+++ b/components/script_bindings/import.rs
@@ -11,12 +11,12 @@ pub(crate) mod base {
};
pub(crate) use js::error::throw_type_error;
pub(crate) use js::jsapi::{
- CurrentGlobalOrNull, HandleValue as RawHandleValue, HandleValueArray, Heap, IsCallable,
- JS_NewObject, JSContext, JSObject,
+ HandleValue as RawHandleValue, HandleValueArray, Heap, IsCallable, JS_NewObject, JSContext,
+ JSObject,
};
pub(crate) use js::jsval::{JSVal, NullValue, ObjectOrNullValue, ObjectValue, UndefinedValue};
pub(crate) use js::panic::maybe_resume_unwind;
- pub(crate) use js::rust::wrappers::{Call, JS_WrapValue};
+ pub(crate) use js::rust::wrappers::Call;
pub(crate) use js::rust::{HandleObject, HandleValue, MutableHandleObject, MutableHandleValue};
pub(crate) use crate::callback::{
diff --git a/components/script_bindings/interfaces.rs b/components/script_bindings/interfaces.rs
index b289737143e..58917283170 100644
--- a/components/script_bindings/interfaces.rs
+++ b/components/script_bindings/interfaces.rs
@@ -3,10 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::RefCell;
-use std::rc::Rc;
use std::thread::LocalKey;
-use js::conversions::ToJSValConvertible;
use js::glue::JSPrincipalsCallbacks;
use js::jsapi::{CallArgs, HandleObject as RawHandleObject, JSContext as RawJSContext, JSObject};
use js::rust::{HandleObject, MutableHandleObject};
@@ -78,14 +76,6 @@ pub trait GlobalScopeHelpers<D: DomTypes> {
unsafe fn from_object(obj: *mut JSObject) -> DomRoot<D::GlobalScope>;
fn from_reflector(reflector: &impl DomObject, realm: InRealm) -> DomRoot<D::GlobalScope>;
- /// # Safety
- /// `obj` must point to a valid, non-null JSObject.
- /// `cx` must point to a valid, non-null RawJSContext.
- unsafe fn from_object_maybe_wrapped(
- obj: *mut JSObject,
- cx: *mut RawJSContext,
- ) -> DomRoot<D::GlobalScope>;
-
fn origin(&self) -> &MutableOrigin;
fn incumbent() -> Option<DomRoot<D::GlobalScope>>;
@@ -101,15 +91,6 @@ pub trait DocumentHelpers {
fn ensure_safe_to_run_script_or_layout(&self);
}
-/// Operations that must be invoked from the generated bindings.
-pub trait PromiseHelpers<D: crate::DomTypes> {
- fn new_resolved(
- global: &D::GlobalScope,
- cx: JSContext,
- value: impl ToJSValConvertible,
- ) -> Rc<D::Promise>;
-}
-
pub trait ServoInternalsHelpers {
fn is_servo_internal(cx: JSContext, global: HandleObject) -> bool;
}
diff --git a/components/script_bindings/webidls/Document.webidl b/components/script_bindings/webidls/Document.webidl
index 737e74d3bf2..e878b1642e4 100644
--- a/components/script_bindings/webidls/Document.webidl
+++ b/components/script_bindings/webidls/Document.webidl
@@ -154,7 +154,6 @@ partial /*sealed*/ interface Document {
// also has obsolete members
};
Document includes GlobalEventHandlers;
-Document includes DocumentAndElementEventHandlers;
// https://html.spec.whatwg.org/multipage/#Document-partial
partial interface Document {
diff --git a/components/script_bindings/webidls/Element.webidl b/components/script_bindings/webidls/Element.webidl
index 0d2e204ae52..42733b91929 100644
--- a/components/script_bindings/webidls/Element.webidl
+++ b/components/script_bindings/webidls/Element.webidl
@@ -82,7 +82,7 @@ interface Element : Node {
[Throws]
undefined insertAdjacentText(DOMString where_, DOMString data);
[CEReactions, Throws]
- undefined insertAdjacentHTML(DOMString position, DOMString html);
+ undefined insertAdjacentHTML(DOMString position, (TrustedHTML or DOMString) string);
[Throws, Pref="dom_shadowdom_enabled"] ShadowRoot attachShadow(ShadowRootInit init);
readonly attribute ShadowRoot? shadowRoot;
@@ -122,11 +122,11 @@ partial interface Element {
// https://html.spec.whatwg.org/multipage/#dom-parsing-and-serialization
partial interface Element {
- [CEReactions] undefined setHTMLUnsafe(DOMString html);
+ [CEReactions, Throws] undefined setHTMLUnsafe((TrustedHTML or DOMString) html);
DOMString getHTML(optional GetHTMLOptions options = {});
- [CEReactions, Throws] attribute [LegacyNullToEmptyString] DOMString innerHTML;
- [CEReactions, Throws] attribute [LegacyNullToEmptyString] DOMString outerHTML;
+ [CEReactions, Throws] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
+ [CEReactions, Throws] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) outerHTML;
};
dictionary GetHTMLOptions {
diff --git a/components/script_bindings/webidls/EventHandler.webidl b/components/script_bindings/webidls/EventHandler.webidl
index f597ce237d3..d32302f4b37 100644
--- a/components/script_bindings/webidls/EventHandler.webidl
+++ b/components/script_bindings/webidls/EventHandler.webidl
@@ -28,6 +28,10 @@ typedef OnBeforeUnloadEventHandlerNonNull? OnBeforeUnloadEventHandler;
[Exposed=Window]
interface mixin GlobalEventHandlers {
attribute EventHandler onabort;
+ attribute EventHandler onauxclick;
+ attribute EventHandler onbeforeinput;
+ attribute EventHandler onbeforematch;
+ attribute EventHandler onbeforetoggle;
attribute EventHandler onblur;
attribute EventHandler oncancel;
attribute EventHandler oncanplay;
@@ -35,13 +39,17 @@ interface mixin GlobalEventHandlers {
attribute EventHandler onchange;
attribute EventHandler onclick;
attribute EventHandler onclose;
+ attribute EventHandler oncommand;
+ attribute EventHandler oncontextlost;
attribute EventHandler oncontextmenu;
+ attribute EventHandler oncontextrestored;
+ attribute EventHandler oncopy;
attribute EventHandler oncuechange;
+ attribute EventHandler oncut;
attribute EventHandler ondblclick;
attribute EventHandler ondrag;
attribute EventHandler ondragend;
attribute EventHandler ondragenter;
- attribute EventHandler ondragexit;
attribute EventHandler ondragleave;
attribute EventHandler ondragover;
attribute EventHandler ondragstart;
@@ -68,7 +76,7 @@ interface mixin GlobalEventHandlers {
attribute EventHandler onmouseout;
attribute EventHandler onmouseover;
attribute EventHandler onmouseup;
- attribute EventHandler onwheel;
+ attribute EventHandler onpaste;
attribute EventHandler onpause;
attribute EventHandler onplay;
attribute EventHandler onplaying;
@@ -77,11 +85,12 @@ interface mixin GlobalEventHandlers {
attribute EventHandler onreset;
attribute EventHandler onresize;
attribute EventHandler onscroll;
+ attribute EventHandler onscrollend;
attribute EventHandler onsecuritypolicyviolation;
attribute EventHandler onseeked;
attribute EventHandler onseeking;
attribute EventHandler onselect;
- attribute EventHandler onshow;
+ attribute EventHandler onslotchange;
attribute EventHandler onstalled;
attribute EventHandler onsubmit;
attribute EventHandler onsuspend;
@@ -89,6 +98,11 @@ interface mixin GlobalEventHandlers {
attribute EventHandler ontoggle;
attribute EventHandler onvolumechange;
attribute EventHandler onwaiting;
+ attribute EventHandler onwebkitanimationend;
+ attribute EventHandler onwebkitanimationiteration;
+ attribute EventHandler onwebkitanimationstart;
+ attribute EventHandler onwebkittransitionend;
+ attribute EventHandler onwheel;
};
// https://drafts.csswg.org/css-animations/#interface-globaleventhandlers-idl
@@ -123,18 +137,12 @@ interface mixin WindowEventHandlers {
attribute EventHandler onoffline;
attribute EventHandler ononline;
attribute EventHandler onpagehide;
+ attribute EventHandler onpagereveal;
attribute EventHandler onpageshow;
+ attribute EventHandler onpageswap;
attribute EventHandler onpopstate;
attribute EventHandler onrejectionhandled;
attribute EventHandler onstorage;
attribute EventHandler onunhandledrejection;
attribute EventHandler onunload;
};
-
-// https://html.spec.whatwg.org/multipage/#documentandelementeventhandlers
-[Exposed=Window]
-interface mixin DocumentAndElementEventHandlers {
- attribute EventHandler oncopy;
- attribute EventHandler oncut;
- attribute EventHandler onpaste;
-};
diff --git a/components/script_bindings/webidls/HTMLElement.webidl b/components/script_bindings/webidls/HTMLElement.webidl
index 76bfada1b94..19a4b515d11 100644
--- a/components/script_bindings/webidls/HTMLElement.webidl
+++ b/components/script_bindings/webidls/HTMLElement.webidl
@@ -73,7 +73,6 @@ partial interface HTMLElement {
};
HTMLElement includes GlobalEventHandlers;
-HTMLElement includes DocumentAndElementEventHandlers;
HTMLElement includes ElementContentEditable;
HTMLElement includes ElementCSSInlineStyle;
HTMLElement includes HTMLOrSVGElement;