Add WebGLContextAttributes support

This commit also:
* Allows to return non-rootable dictionaries from
Codegen.
* Merges the two context types in an enum type.
This commit is contained in:
ecoal95 2015-05-25 14:47:23 +02:00
parent b1a773a15b
commit b3ac346749
16 changed files with 255 additions and 80 deletions

View file

@ -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 {