diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-06-01 08:37:48 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-06-01 08:37:48 -0500 |
commit | 0de09b936e5e37c15b7865157a98ad78b1077659 (patch) | |
tree | dff9058ec210d968aae1031632dede080456db88 /components/script/dom/bindings/utils.rs | |
parent | 2a8d5952892e050a3d604741dd1007e3bd563315 (diff) | |
parent | b3ac3467494377569997126103005382793d8081 (diff) | |
download | servo-0de09b936e5e37c15b7865157a98ad78b1077659.tar.gz servo-0de09b936e5e37c15b7865157a98ad78b1077659.zip |
Auto merge of #6183 - ecoal95:webglcontextattributes, r=nox
r? @jdm
I couldn't add the `getContextAttributes` method since `CodegenRust`
doesn't know how to return a dictionary value, I'll take a look at it ASAP.
I think the helper functions can return directly the renderer, since they're used just for that, but I wanted to hear your opinions about this.
By the way I'm interested in adding more serious tests for WebGL, and I think the [khronos conformance suit](https://github.com/KhronosGroup/WebGL/tree/master/conformance-suites/1.0.3) should be the best option.
Should I try to integrate it in wpt, or making a `tests/webgl` directory (or similar) inside the servo tree? (Maybe this question should be for @Ms2ger)
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6183)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r-- | components/script/dom/bindings/utils.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 612cba46f35..f53451352cc 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -29,7 +29,7 @@ use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAn use js::jsapi::JSHandleObject; use js::jsapi::JS_GetFunctionObject; use js::jsapi::{JS_HasPropertyById, JS_GetPrototype}; -use js::jsapi::{JS_GetProperty, JS_HasProperty}; +use js::jsapi::{JS_GetProperty, JS_HasProperty, JS_SetProperty}; use js::jsapi::{JS_DefineFunctions, JS_DefineProperty}; use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot}; use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass}; @@ -510,7 +510,6 @@ pub fn is_platform_object(obj: *mut JSObject) -> bool { pub fn get_dictionary_property(cx: *mut JSContext, object: *mut JSObject, property: &str) -> Result<Option<JSVal>, ()> { - use std::ffi::CString; fn has_property(cx: *mut JSContext, object: *mut JSObject, property: &CString, found: &mut JSBool) -> bool { unsafe { @@ -546,6 +545,27 @@ pub fn get_dictionary_property(cx: *mut JSContext, Ok(Some(value)) } +/// Set the property with name `property` from `object`. +/// Returns `Err(())` on JSAPI failure, or null object, +/// and Ok(()) otherwise +pub fn set_dictionary_property(cx: *mut JSContext, + object: *mut JSObject, + property: &str, + value: &mut JSVal) -> Result<(), ()> { + if object.is_null() { + return Err(()); + } + + let property = CString::new(property).unwrap(); + unsafe { + if JS_SetProperty(cx, object, property.as_ptr(), value) == 0 { + return Err(()); + } + } + + Ok(()) +} + /// Returns whether `proxy` has a property `id` on its prototype. pub fn has_property_on_prototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> bool { |