diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-01-08 08:48:54 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-01-08 08:48:54 -0700 |
commit | df6a7959df69bf98b397f088fc3cf1fad2cc0aaf (patch) | |
tree | fae7131eb701121982eab0b793730a4c17615ef3 /components/script/dom/bindings | |
parent | 1d7148c79f9124779a910fd5291c5fa0543b2dae (diff) | |
parent | 5fe3a3e54f2d94c33ca84c54521aab4bd6b98c1e (diff) | |
download | servo-df6a7959df69bf98b397f088fc3cf1fad2cc0aaf.tar.gz servo-df6a7959df69bf98b397f088fc3cf1fad2cc0aaf.zip |
auto merge of #4069 : guillaumebort/servo/fix/3936, r=jdm
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 3 | ||||
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/utils.rs | 27 |
3 files changed, 28 insertions, 4 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 4d8dd7599c5..a256432f762 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -336,7 +336,7 @@ class CGMethodCall(CGThing): # Check for vanilla JS objects # XXXbz Do we need to worry about security wrappers? - pickFirstSignature("%s.isObject() && !IsPlatformObject(cx, &%s.toObject())" % + pickFirstSignature("%s.is_object() && !IsPlatformObject(%s.to_object())" % (distinguishingArg, distinguishingArg), lambda s: (s[1][distinguishingIndex].type.isCallback() or s[1][distinguishingIndex].type.isCallbackInterface() or @@ -4552,6 +4552,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}', 'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}', 'dom::bindings::utils::HasPropertyOnPrototype', + 'dom::bindings::utils::IsPlatformObject', 'dom::bindings::utils::{Reflectable}', 'dom::bindings::utils::{squirrel_away_unique}', 'dom::bindings::utils::{ThrowingConstructor}', diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 446b2b27829..ddfff41f8f5 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -353,7 +353,7 @@ impl ToJSValConvertible for Reflector { } /// Returns whether the given `clasp` is one for a DOM object. -fn is_dom_class(clasp: *const JSClass) -> bool { +pub fn is_dom_class(clasp: *const JSClass) -> bool { unsafe { ((*clasp).flags & js::JSCLASS_IS_DOMJSCLASS) != 0 } diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 6986ddaf344..13d662ae5f7 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::PrototypeList; use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH; -use dom::bindings::conversions::unwrap_jsmanaged; +use dom::bindings::conversions::{unwrap_jsmanaged, is_dom_class}; use dom::bindings::error::throw_type_error; use dom::bindings::global::GlobalRef; use dom::bindings::js::{Temporary, Root}; @@ -20,7 +20,8 @@ use libc::c_uint; use std::cell::Cell; use std::mem; use std::ptr; -use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT}; +use js::glue::UnwrapObject; +use js::glue::{IsWrapper, RUST_JSID_IS_INT, RUST_JSID_TO_INT}; use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction}; use js::jsapi::{JS_DefineProperties, JS_ForwardGetPropertyTo}; use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength}; @@ -466,6 +467,28 @@ pub fn FindEnumStringIndex(cx: *mut JSContext, } } +/// Returns wether `obj` is a platform object +/// http://heycam.github.io/webidl/#dfn-platform-object +pub fn IsPlatformObject(obj: *mut JSObject) -> bool { + unsafe { + // Fast-path the common case + let mut clasp = JS_GetClass(obj); + if is_dom_class(&*clasp) { + return true; + } + // Now for simplicity check for security wrappers before anything else + if IsWrapper(obj) == 1 { + let unwrapped_obj = UnwrapObject(obj, /* stopAtOuter = */ 0, ptr::null_mut()); + if unwrapped_obj.is_null() { + return false; + } + clasp = js::jsapi::JS_GetClass(obj); + } + // TODO also check if JS_IsArrayBufferObject + return is_dom_class(&*clasp); + } +} + /// Get the property with name `property` from `object`. /// Returns `Err(())` on JSAPI failure (there is a pending exception), and /// `Ok(None)` if there was no property with the given name. |