mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Miscellaneous script splitting preparation changes (#36216)
* script: Move num module to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Make JS reflector creation generic over DOM trait. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move bindings-specific lock to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move DOM proto array code to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move finalizer implementations to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move some error routines to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move some DOM interface conversion routines to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Make is_array_like generic over DOM trait. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Use generic interfaces for conditional exposure functions. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move a bunch of routines used by codegen to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
2c94110952
commit
c30ad5a30e
28 changed files with 836 additions and 691 deletions
|
@ -2,6 +2,12 @@
|
|||
* 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/. */
|
||||
|
||||
use js::error::throw_type_error;
|
||||
use js::jsapi::JS_IsExceptionPending;
|
||||
|
||||
use crate::codegen::PrototypeList::proto_id_to_name;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
|
||||
/// DOM exceptions that can be thrown by a native DOM method.
|
||||
#[derive(Clone, Debug, MallocSizeOf)]
|
||||
pub enum Error {
|
||||
|
@ -69,3 +75,20 @@ pub type Fallible<T> = Result<T, Error>;
|
|||
/// The return type for IDL operations that can throw DOM exceptions and
|
||||
/// return `()`.
|
||||
pub type ErrorResult = Fallible<()>;
|
||||
|
||||
/// Throw an exception to signal that a `JSObject` can not be converted to a
|
||||
/// given DOM type.
|
||||
pub fn throw_invalid_this(cx: SafeJSContext, proto_id: u16) {
|
||||
debug_assert!(unsafe { !JS_IsExceptionPending(*cx) });
|
||||
let error = format!(
|
||||
"\"this\" object does not implement interface {}.",
|
||||
proto_id_to_name(proto_id)
|
||||
);
|
||||
unsafe { throw_type_error(*cx, &error) };
|
||||
}
|
||||
|
||||
pub fn throw_constructor_without_new(cx: SafeJSContext, name: &str) {
|
||||
debug_assert!(unsafe { !JS_IsExceptionPending(*cx) });
|
||||
let error = format!("{} constructor: 'new' is required", name);
|
||||
unsafe { throw_type_error(*cx, &error) };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue