mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Replace NonZero<*mut JSObject> with a wrapper to enable local trait impls.
This commit is contained in:
parent
115d859551
commit
e2fafd2dfc
22 changed files with 108 additions and 69 deletions
|
@ -4,18 +4,18 @@
|
|||
|
||||
use canvas_traits::webgl::WebGLError;
|
||||
use core::iter::FromIterator;
|
||||
use core::nonzero::NonZero;
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
|
||||
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||
use dom::bindings::nonnull::NonNullJSObjectPtr;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use fnv::{FnvHashMap, FnvHashSet};
|
||||
use gleam::gl::GLenum;
|
||||
use heapsize::HeapSizeOf;
|
||||
use js::jsapi::{JSContext, JSObject};
|
||||
use js::jsapi::JSContext;
|
||||
use js::jsval::JSVal;
|
||||
use ref_filter_map::ref_filter_map;
|
||||
use std::cell::Ref;
|
||||
|
@ -109,7 +109,7 @@ impl WebGLExtensions {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonZero<*mut JSObject>> {
|
||||
pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonNullJSObjectPtr> {
|
||||
let name = name.to_uppercase();
|
||||
self.extensions.borrow().get(&name).and_then(|extension| {
|
||||
if extension.is_supported(self) {
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
* 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/. */
|
||||
|
||||
use core::nonzero::NonZero;
|
||||
use dom::bindings::nonnull::NonNullJSObjectPtr;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||
use heapsize::HeapSizeOf;
|
||||
use js::jsapi::JSObject;
|
||||
use std::any::Any;
|
||||
use super::{WebGLExtension, WebGLExtensions};
|
||||
|
||||
|
@ -18,7 +17,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + HeapSizeOf {
|
|||
fn instance_or_init(&self,
|
||||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions)
|
||||
-> NonZero<*mut JSObject>;
|
||||
-> NonNullJSObjectPtr;
|
||||
fn is_supported(&self, &WebGLExtensions) -> bool;
|
||||
fn is_enabled(&self) -> bool;
|
||||
fn enable(&self, ext: &WebGLExtensions);
|
||||
|
@ -48,7 +47,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
|
|||
fn instance_or_init(&self,
|
||||
ctx: &WebGLRenderingContext,
|
||||
ext: &WebGLExtensions)
|
||||
-> NonZero<*mut JSObject> {
|
||||
-> NonNullJSObjectPtr {
|
||||
let mut enabled = true;
|
||||
let extension = self.extension.or_init(|| {
|
||||
enabled = false;
|
||||
|
@ -58,7 +57,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
|
|||
self.enable(ext);
|
||||
}
|
||||
unsafe {
|
||||
NonZero::new_unchecked(extension.reflector().get_jsobject().get())
|
||||
NonNullJSObjectPtr::new_unchecked(extension.reflector().get_jsobject().get())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue