aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r--components/script/dom/bindings/callback.rs26
-rw-r--r--components/script/dom/bindings/codegen/Bindings.conf16
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py5
-rw-r--r--components/script/dom/bindings/codegen/run.py2
-rw-r--r--components/script/dom/bindings/function.rs50
-rw-r--r--components/script/dom/bindings/import.rs2
-rw-r--r--components/script/dom/bindings/interface.rs1
-rw-r--r--components/script/dom/bindings/mod.rs1
8 files changed, 95 insertions, 8 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs
index 374627c16da..bb4e59ba75c 100644
--- a/components/script/dom/bindings/callback.rs
+++ b/components/script/dom/bindings/callback.rs
@@ -15,7 +15,7 @@ use js::jsapi::{
};
use js::jsval::{JSVal, ObjectValue, UndefinedValue};
use js::rust::wrappers::{JS_GetProperty, JS_WrapObject};
-use js::rust::{MutableHandleObject, Runtime};
+use js::rust::{HandleObject, MutableHandleObject, Runtime};
use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
use crate::dom::bindings::error::{report_pending_exception, Error, Fallible};
@@ -205,9 +205,29 @@ impl CallbackInterface {
}
}
+pub trait ThisReflector {
+ fn jsobject(&self) -> *mut JSObject;
+}
+
+impl<T: DomObject> ThisReflector for T {
+ fn jsobject(&self) -> *mut JSObject {
+ self.reflector().get_jsobject().get()
+ }
+}
+
+impl<'a> ThisReflector for HandleObject<'a> {
+ fn jsobject(&self) -> *mut JSObject {
+ self.get()
+ }
+}
+
/// Wraps the reflector for `p` into the realm of `cx`.
-pub fn wrap_call_this_object<T: DomObject>(cx: JSContext, p: &T, mut rval: MutableHandleObject) {
- rval.set(p.reflector().get_jsobject().get());
+pub fn wrap_call_this_object<T: ThisReflector>(
+ cx: JSContext,
+ p: &T,
+ mut rval: MutableHandleObject,
+) {
+ rval.set(p.jsobject());
assert!(!rval.get().is_null());
unsafe {
diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf
index f4e2c9e2dfb..d0635ead024 100644
--- a/components/script/dom/bindings/codegen/Bindings.conf
+++ b/components/script/dom/bindings/codegen/Bindings.conf
@@ -538,6 +538,22 @@ DOMInterfaces = {
'canGc': ['SimulateDeviceConnection', 'DisconnectAllDevices'],
},
+'ReadableStream': {
+ 'canGc': ['GetReader', 'Cancel', 'Tee'],
+},
+
+"ReadableStreamDefaultController": {
+ "canGc": ["Enqueue"]
+},
+
+"ReadableStreamBYOBReader": {
+ "canGc": ["Read", "Closed", "Cancel"]
+},
+
+"ReadableStreamDefaultReader": {
+ "canGc": ["Read", "Cancel"]
+},
+
}
Dictionaries = {
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index e25ed68d3e8..a0f926b4c50 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -933,6 +933,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
"""
{
use crate::realms::{AlreadyInRealm, InRealm};
+ use crate::dom::readablestream::ReadableStream;
let in_realm_proof = AlreadyInRealm::assert_for_cx(cx);
match ReadableStream::from_js(cx, $${val}.get().to_object(), InRealm::Already(&in_realm_proof)) {
Ok(val) => val,
@@ -949,7 +950,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
templateBody = wrapObjectTemplate(templateBody, "None",
isDefinitelyObject, type, failureCode)
- declType = CGGeneric("DomRoot<ReadableStream>")
+ declType = CGGeneric("DomRoot<dom::readablestream::ReadableStream>")
return handleOptional(templateBody, declType,
handleDefault("None"))
@@ -7718,7 +7719,7 @@ class CGCallback(CGClass):
f"unsafe {{ self.{method.name}({', '.join(argnamesWithoutThis)}) }}")
return [ClassMethod(f'{method.name}_', method.returnType, args,
bodyInHeader=True,
- templateArgs=["T: DomObject"],
+ templateArgs=["T: ThisReflector"],
body=bodyWithThis,
visibility='pub'),
ClassMethod(f'{method.name}__', method.returnType, argsWithoutThis,
diff --git a/components/script/dom/bindings/codegen/run.py b/components/script/dom/bindings/codegen/run.py
index 2dee39814b2..400d022a167 100644
--- a/components/script/dom/bindings/codegen/run.py
+++ b/components/script/dom/bindings/codegen/run.py
@@ -30,7 +30,7 @@ def main():
from Configuration import Configuration
from CodegenRust import CGBindingRoot
- parser = WebIDL.Parser(make_dir(os.path.join(out_dir, "cache")))
+ parser = WebIDL.Parser(make_dir(os.path.join(out_dir, "cache")), use_builtin_readable_stream=False)
webidls = [name for name in os.listdir(webidls_dir) if name.endswith(".webidl")]
for webidl in webidls:
filename = os.path.join(webidls_dir, webidl)
diff --git a/components/script/dom/bindings/function.rs b/components/script/dom/bindings/function.rs
new file mode 100644
index 00000000000..86f4903b07d
--- /dev/null
+++ b/components/script/dom/bindings/function.rs
@@ -0,0 +1,50 @@
+/* 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 http://mozilla.org/MPL/2.0/. */
+
+/// Defines a macro `native_fn!` to create a JavaScript function from a Rust function pointer.
+/// # Example
+/// ```
+/// let js_function: Rc<Function> = native_fn!(my_rust_function, c"myFunction", 2, 0);
+/// ```
+#[macro_export]
+macro_rules! native_fn {
+ ($call:expr, $name:expr, $nargs:expr, $flags:expr) => {{
+ let cx = $crate::dom::types::GlobalScope::get_cx();
+ let fun_obj = $crate::native_raw_obj_fn!(cx, $call, $name, $nargs, $flags);
+ #[allow(unsafe_code)]
+ unsafe {
+ Function::new(cx, fun_obj)
+ }
+ }};
+}
+
+/// Defines a macro `native_raw_obj_fn!` to create a raw JavaScript function object.
+/// # Example
+/// ```
+/// let raw_function_obj: *mut JSObject = native_raw_obj_fn!(cx, my_rust_function, c"myFunction", 2, 0);
+/// ```
+#[macro_export]
+macro_rules! native_raw_obj_fn {
+ ($cx:expr, $call:expr, $name:expr, $nargs:expr, $flags:expr) => {{
+ #[allow(unsafe_code)]
+ #[allow(clippy::macro_metavars_in_unsafe)]
+ unsafe extern "C" fn wrapper(cx: *mut JSContext, argc: u32, vp: *mut JSVal) -> bool {
+ $call(cx, argc, vp)
+ }
+ #[allow(unsafe_code)]
+ #[allow(clippy::macro_metavars_in_unsafe)]
+ unsafe {
+ let name: &std::ffi::CStr = $name;
+ let raw_fun = $crate::dom::bindings::import::module::jsapi::JS_NewFunction(
+ *$cx,
+ Some(wrapper),
+ $nargs,
+ $flags,
+ name.as_ptr() as *const std::ffi::c_char,
+ );
+ assert!(!raw_fun.is_null());
+ $crate::dom::bindings::import::module::jsapi::JS_GetFunctionObject(raw_fun)
+ }
+ }};
+}
diff --git a/components/script/dom/bindings/import.rs b/components/script/dom/bindings/import.rs
index 0d9f0d70fdf..c4586b43905 100644
--- a/components/script/dom/bindings/import.rs
+++ b/components/script/dom/bindings/import.rs
@@ -19,7 +19,7 @@ pub mod base {
pub use crate::dom::bindings::callback::{
wrap_call_this_object, CallSetup, CallbackContainer, CallbackFunction, CallbackInterface,
- CallbackObject, ExceptionHandling,
+ CallbackObject, ExceptionHandling, ThisReflector,
};
pub use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
ChannelCountMode, ChannelCountModeValues, ChannelInterpretation,
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index ce2f7e275b6..bf2fc6faa87 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -146,7 +146,6 @@ pub unsafe fn create_global_object(
let mut options = RealmOptions::default();
options.creationOptions_.traceGlobal_ = Some(trace);
options.creationOptions_.sharedMemoryAndAtomics_ = false;
- options.creationOptions_.streams_ = true;
select_compartment(cx, &mut options);
let principal = ServoJSPrincipals::new(origin);
diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs
index a6666b70d90..633763f1ba6 100644
--- a/components/script/dom/bindings/mod.rs
+++ b/components/script/dom/bindings/mod.rs
@@ -143,6 +143,7 @@ pub mod conversions;
pub mod error;
pub mod finalize;
pub mod frozenarray;
+pub mod function;
pub mod guard;
pub mod import;
pub mod inheritance;