mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Convert CGTraitInterface to use safe JSContext instead of raw JSContext
This commit is contained in:
parent
808fa65aef
commit
2c5d0a6ebc
43 changed files with 443 additions and 528 deletions
|
@ -49,6 +49,7 @@ use crate::dom::globalscope::GlobalScope;
|
|||
use crate::dom::promise::Promise;
|
||||
use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler};
|
||||
use crate::dom::url::URL;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use crate::timers::OneshotTimerCallback;
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSContext, JSObject};
|
||||
|
@ -215,23 +216,24 @@ impl TestBindingMethods for TestBinding {
|
|||
}
|
||||
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
||||
NonNull::new(array.get()).expect("got a null pointer")
|
||||
fn ArrayAttribute(&self, cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
unsafe {
|
||||
rooted!(in(*cx) let array = JS_NewUint8ClampedArray(*cx, 16));
|
||||
NonNull::new(array.get()).expect("got a null pointer")
|
||||
}
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal {
|
||||
fn AnyAttribute(&self, _: SafeJSContext) -> JSVal {
|
||||
NullValue()
|
||||
}
|
||||
fn SetAnyAttribute(&self, _: SafeJSContext, _: HandleValue) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
||||
NonNull::new(obj.get()).expect("got a null pointer")
|
||||
fn ObjectAttribute(&self, cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
unsafe {
|
||||
rooted!(in(*cx) let obj = JS_NewPlainObject(*cx));
|
||||
NonNull::new(obj.get()).expect("got a null pointer")
|
||||
}
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn SetObjectAttribute(&self, _: SafeJSContext, _: *mut JSObject) {}
|
||||
|
||||
fn GetBooleanAttributeNullable(&self) -> Option<bool> {
|
||||
Some(false)
|
||||
|
@ -329,12 +331,10 @@ impl TestBindingMethods for TestBinding {
|
|||
fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
|
||||
self.url.set(url);
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonNull<JSObject>> {
|
||||
fn GetObjectAttributeNullable(&self, _: SafeJSContext) -> Option<NonNull<JSObject>> {
|
||||
None
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn SetObjectAttributeNullable(&self, _: SafeJSContext, _: *mut JSObject) {}
|
||||
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
|
||||
Some(HTMLElementOrLong::Long(0))
|
||||
}
|
||||
|
@ -419,12 +419,10 @@ impl TestBindingMethods for TestBinding {
|
|||
"".to_owned(),
|
||||
)
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ReceiveAny(&self, _: *mut JSContext) -> JSVal {
|
||||
fn ReceiveAny(&self, _: SafeJSContext) -> JSVal {
|
||||
NullValue()
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||
fn ReceiveObject(&self, cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
self.ObjectAttribute(cx)
|
||||
}
|
||||
fn ReceiveUnion(&self) -> HTMLElementOrLong {
|
||||
|
@ -470,10 +468,9 @@ impl TestBindingMethods for TestBinding {
|
|||
"".to_owned(),
|
||||
)]
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ReceiveUnionIdentity(
|
||||
fn ReceiveUnionIdentity(
|
||||
&self,
|
||||
_: *mut JSContext,
|
||||
_: SafeJSContext,
|
||||
arg: UnionTypes::StringOrObject,
|
||||
) -> UnionTypes::StringOrObject {
|
||||
arg
|
||||
|
@ -537,8 +534,7 @@ impl TestBindingMethods for TestBinding {
|
|||
"".to_owned(),
|
||||
))
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonNull<JSObject>> {
|
||||
fn ReceiveNullableObject(&self, cx: SafeJSContext) -> Option<NonNull<JSObject>> {
|
||||
self.GetObjectAttributeNullable(cx)
|
||||
}
|
||||
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
|
||||
|
@ -666,35 +662,24 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassUnion7(&self, _: StringSequenceOrUnsignedLong) {}
|
||||
fn PassUnion8(&self, _: ByteStringSequenceOrLong) {}
|
||||
fn PassUnion9(&self, _: UnionTypes::TestDictionaryOrLong) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassUnion10(&self, _: *mut JSContext, _: UnionTypes::StringOrObject) {}
|
||||
fn PassUnion10(&self, _: SafeJSContext, _: UnionTypes::StringOrObject) {}
|
||||
fn PassUnion11(&self, _: UnionTypes::ArrayBufferOrArrayBufferView) {}
|
||||
fn PassUnionWithTypedef(&self, _: DocumentOrTestTypedef) {}
|
||||
fn PassUnionWithTypedef2(&self, _: LongSequenceOrTestTypedef) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassAny(&self, _: *mut JSContext, _: HandleValue) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn PassAny(&self, _: SafeJSContext, _: HandleValue) {}
|
||||
fn PassObject(&self, _: SafeJSContext, _: *mut JSObject) {}
|
||||
fn PassCallbackFunction(&self, _: Rc<Function>) {}
|
||||
fn PassCallbackInterface(&self, _: Rc<EventListener>) {}
|
||||
fn PassSequence(&self, _: Vec<i32>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassAnySequence(&self, _: *mut JSContext, _: CustomAutoRooterGuard<Vec<JSVal>>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn AnySequencePassthrough(
|
||||
fn PassAnySequence(&self, _: SafeJSContext, _: CustomAutoRooterGuard<Vec<JSVal>>) {}
|
||||
fn AnySequencePassthrough(
|
||||
&self,
|
||||
_: *mut JSContext,
|
||||
_: SafeJSContext,
|
||||
seq: CustomAutoRooterGuard<Vec<JSVal>>,
|
||||
) -> Vec<JSVal> {
|
||||
(*seq).clone()
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassObjectSequence(
|
||||
&self,
|
||||
_: *mut JSContext,
|
||||
_: CustomAutoRooterGuard<Vec<*mut JSObject>>,
|
||||
) {
|
||||
}
|
||||
fn PassObjectSequence(&self, _: SafeJSContext, _: CustomAutoRooterGuard<Vec<*mut JSObject>>) {}
|
||||
fn PassStringSequence(&self, _: Vec<DOMString>) {}
|
||||
fn PassInterfaceSequence(&self, _: Vec<DomRoot<Blob>>) {}
|
||||
|
||||
|
@ -719,8 +704,7 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassNullableByteString(&self, _: Option<ByteString>) {}
|
||||
// fn PassNullableEnum(self, _: Option<TestEnum>) {}
|
||||
fn PassNullableInterface(&self, _: Option<&Blob>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassNullableObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn PassNullableObject(&self, _: SafeJSContext, _: *mut JSObject) {}
|
||||
fn PassNullableTypedArray(&self, _: CustomAutoRooterGuard<Option<typedarray::Int8Array>>) {}
|
||||
fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
|
||||
fn PassNullableUnion2(&self, _: Option<EventOrString>) {}
|
||||
|
@ -756,10 +740,8 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassOptionalUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
|
||||
fn PassOptionalUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
|
||||
fn PassOptionalUnion6(&self, _: Option<ByteStringOrLong>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassOptionalAny(&self, _: *mut JSContext, _: HandleValue) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassOptionalObject(&self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
||||
fn PassOptionalAny(&self, _: SafeJSContext, _: HandleValue) {}
|
||||
fn PassOptionalObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {}
|
||||
fn PassOptionalCallbackFunction(&self, _: Option<Rc<Function>>) {}
|
||||
fn PassOptionalCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
|
||||
fn PassOptionalSequence(&self, _: Option<Vec<i32>>) {}
|
||||
|
@ -782,8 +764,7 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
||||
// fn PassOptionalNullableEnum(self, _: Option<Option<TestEnum>>) {}
|
||||
fn PassOptionalNullableInterface(&self, _: Option<Option<&Blob>>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassOptionalNullableObject(&self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
||||
fn PassOptionalNullableObject(&self, _: SafeJSContext, _: Option<*mut JSObject>) {}
|
||||
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
|
||||
fn PassOptionalNullableUnion2(&self, _: Option<Option<EventOrString>>) {}
|
||||
fn PassOptionalNullableUnion3(&self, _: Option<Option<StringOrLongSequence>>) {}
|
||||
|
@ -827,14 +808,12 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassOptionalNullableByteStringWithDefault(&self, _: Option<ByteString>) {}
|
||||
// fn PassOptionalNullableEnumWithDefault(self, _: Option<TestEnum>) {}
|
||||
fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<&Blob>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassOptionalNullableObjectWithDefault(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn PassOptionalNullableObjectWithDefault(&self, _: SafeJSContext, _: *mut JSObject) {}
|
||||
fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
|
||||
fn PassOptionalNullableUnion2WithDefault(&self, _: Option<EventOrString>) {}
|
||||
// fn PassOptionalNullableCallbackFunctionWithDefault(self, _: Option<Function>) {}
|
||||
fn PassOptionalNullableCallbackInterfaceWithDefault(&self, _: Option<Rc<EventListener>>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassOptionalAnyWithDefault(&self, _: *mut JSContext, _: HandleValue) {}
|
||||
fn PassOptionalAnyWithDefault(&self, _: SafeJSContext, _: HandleValue) {}
|
||||
|
||||
fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
||||
fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
||||
|
@ -883,10 +862,8 @@ impl TestBindingMethods for TestBinding {
|
|||
fn PassVariadicUnion5(&self, _: Vec<StringOrUnsignedLong>) {}
|
||||
fn PassVariadicUnion6(&self, _: Vec<UnsignedLongOrBoolean>) {}
|
||||
fn PassVariadicUnion7(&self, _: Vec<ByteStringOrLong>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassVariadicAny(&self, _: *mut JSContext, _: Vec<HandleValue>) {}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PassVariadicObject(&self, _: *mut JSContext, _: Vec<*mut JSObject>) {}
|
||||
fn PassVariadicAny(&self, _: SafeJSContext, _: Vec<HandleValue>) {}
|
||||
fn PassVariadicObject(&self, _: SafeJSContext, _: Vec<*mut JSObject>) {}
|
||||
fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
|
||||
prefs::pref_map()
|
||||
.get(pref_name.as_ref())
|
||||
|
@ -965,32 +942,28 @@ impl TestBindingMethods for TestBinding {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ReturnResolvedPromise(
|
||||
&self,
|
||||
cx: *mut JSContext,
|
||||
v: HandleValue,
|
||||
) -> Fallible<Rc<Promise>> {
|
||||
Promise::new_resolved(&self.global(), cx, v)
|
||||
fn ReturnResolvedPromise(&self, cx: SafeJSContext, v: HandleValue) -> Fallible<Rc<Promise>> {
|
||||
unsafe { Promise::new_resolved(&self.global(), *cx, v) }
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ReturnRejectedPromise(
|
||||
&self,
|
||||
cx: *mut JSContext,
|
||||
v: HandleValue,
|
||||
) -> Fallible<Rc<Promise>> {
|
||||
Promise::new_rejected(&self.global(), cx, v)
|
||||
fn ReturnRejectedPromise(&self, cx: SafeJSContext, v: HandleValue) -> Fallible<Rc<Promise>> {
|
||||
unsafe { Promise::new_rejected(&self.global(), *cx, v) }
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PromiseResolveNative(&self, cx: *mut JSContext, p: &Promise, v: HandleValue) {
|
||||
p.resolve(cx, v);
|
||||
fn PromiseResolveNative(&self, cx: SafeJSContext, p: &Promise, v: HandleValue) {
|
||||
unsafe {
|
||||
p.resolve(*cx, v);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn PromiseRejectNative(&self, cx: *mut JSContext, p: &Promise, v: HandleValue) {
|
||||
p.reject(cx, v);
|
||||
fn PromiseRejectNative(&self, cx: SafeJSContext, p: &Promise, v: HandleValue) {
|
||||
unsafe {
|
||||
p.reject(*cx, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn PromiseRejectWithTypeError(&self, p: &Promise, s: USVString) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue