mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Generate code for handling callbacks. Implement add/removeEventListener and hacky dispatchEvent proof-of-concept.
This commit is contained in:
parent
06b1db8818
commit
7ecf5abbbd
18 changed files with 491 additions and 331 deletions
|
@ -4,8 +4,8 @@
|
|||
|
||||
use dom::bindings::codegen::PrototypeList;
|
||||
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
|
||||
use dom::window;
|
||||
use dom::node::{AbstractNode, ScriptView};
|
||||
use dom::window;
|
||||
|
||||
use std::libc::c_uint;
|
||||
use std::cast;
|
||||
|
@ -22,6 +22,7 @@ use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFam
|
|||
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction, JS_GetGlobalObject};
|
||||
use js::jsapi::{JS_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo};
|
||||
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
|
||||
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate};
|
||||
use js::jsapi::{JS_GetFunctionPrototype, JS_InternString, JS_GetFunctionObject};
|
||||
use js::jsapi::{JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject};
|
||||
use js::jsapi::{JS_NewUCStringCopyN, JS_DefineFunctions, JS_DefineProperty};
|
||||
|
@ -30,7 +31,7 @@ use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
|
|||
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
|
||||
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
|
||||
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
||||
use js::{JSPROP_ENUMERATE, JSVAL_NULL};
|
||||
use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
||||
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
|
||||
use js::{JSPROP_SETTER, JSVAL_VOID, JSVAL_TRUE, JSVAL_FALSE};
|
||||
use js::{JS_THIS_OBJECT, JSFUN_CONSTRUCTOR, JS_CALLEE, JSPROP_READONLY};
|
||||
|
@ -819,6 +820,13 @@ pub fn HasPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid) -> boo
|
|||
return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::null()) || found;
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn IsConvertibleToCallbackInterface(cx: *JSContext, obj: *JSObject) -> bool {
|
||||
unsafe {
|
||||
JS_ObjectIsDate(cx, obj) == 0 && JS_ObjectIsRegExp(cx, obj) == 0
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
||||
unsafe {
|
||||
|
@ -832,6 +840,30 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn cx_for_dom_wrapper(obj: *JSObject) -> *JSContext {
|
||||
unsafe {
|
||||
let global = GetGlobalForObjectCrossCompartment(obj);
|
||||
let clasp = JS_GetClass(global);
|
||||
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
||||
//XXXjdm either don't hardcode or sanity assert prototype stuff
|
||||
let win = unwrap_object::<*Box<window::Window>>(global, PrototypeList::id::Window, 1);
|
||||
match win {
|
||||
Ok(win) => {
|
||||
match (*win).data.page.js_info {
|
||||
Some(ref info) => info.js_context.ptr,
|
||||
None => fail!("no JS context for DOM global")
|
||||
}
|
||||
}
|
||||
Err(_) => fail!("found DOM global that doesn't unwrap to Window")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cx_for_dom_object<T: Reflectable>(obj: @mut T) -> *JSContext {
|
||||
cx_for_dom_wrapper(obj.reflector().get_jsobject())
|
||||
}
|
||||
|
||||
/// Check if an element name is valid. See http://www.w3.org/TR/xml/#NT-Name
|
||||
/// for details.
|
||||
pub fn is_valid_element_name(name: &str) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue