aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-08-24 19:29:56 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-08-25 14:03:07 +0200
commita4f2159e36a04b6ab7fe0219d6569dc79f5c98c0 (patch)
tree77fbc3528b114f6a74b3a7feeaad92b77eb21e8a
parent32a600246e95099ae5f93a4532133c393e7b6afb (diff)
downloadservo-a4f2159e36a04b6ab7fe0219d6569dc79f5c98c0.tar.gz
servo-a4f2159e36a04b6ab7fe0219d6569dc79f5c98c0.zip
Rename utils::create_dom_object to interface::create_global_object
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py30
-rw-r--r--components/script/dom/bindings/interface.rs71
-rw-r--r--components/script/dom/bindings/utils.rs56
3 files changed, 80 insertions, 77 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index ef4015b53b7..03eb8e1704e 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2514,11 +2514,11 @@ let raw = Box::into_raw(object);
let _rt = RootedTraceable::new(&*raw);
rooted!(in(cx) let obj =
- create_dom_global(
+ create_global_object(
cx,
&Class.base as *const js::jsapi::Class as *const _,
raw as *const libc::c_void,
- Some(_trace)));
+ _trace));
assert!(!obj.is_null());
(*raw).init_reflector(obj.get());
@@ -5294,26 +5294,26 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'dom::bindings',
'dom::bindings::codegen::InterfaceObjectMap',
'dom::bindings::global::{GlobalRef, global_root_from_object, global_root_from_reflector}',
- 'dom::bindings::interface::{InterfaceConstructorBehavior, NonCallbackInterfaceObjectClass}',
- 'dom::bindings::interface::{create_callback_interface_object, create_interface_prototype_object}',
- 'dom::bindings::interface::{create_named_constructors, create_noncallback_interface_object}',
- 'dom::bindings::interface::{define_guarded_methods, define_guarded_properties}',
- 'dom::bindings::interface::{ConstantSpec, NonNullJSNative}',
+ 'dom::bindings::interface::{ConstantSpec, InterfaceConstructorBehavior}',
+ 'dom::bindings::interface::{NonCallbackInterfaceObjectClass, NonNullJSNative}',
+ 'dom::bindings::interface::{create_callback_interface_object, create_global_object}',
+ 'dom::bindings::interface::{create_interface_prototype_object, create_named_constructors}',
+ 'dom::bindings::interface::{create_noncallback_interface_object, define_guarded_methods}',
+ 'dom::bindings::interface::{define_guarded_properties, is_exposed_in}',
'dom::bindings::interface::ConstantVal::{IntVal, UintVal}',
- 'dom::bindings::interface::is_exposed_in',
'dom::bindings::iterable::{IteratorType, Iterable}',
'dom::bindings::js::{JS, Root, RootedReference}',
'dom::bindings::js::{OptionalRootedReference}',
'dom::bindings::reflector::{Reflectable}',
'dom::bindings::utils::{DOMClass, DOMJSClass}',
'dom::bindings::utils::{DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, JSCLASS_DOM_GLOBAL}',
- 'dom::bindings::utils::{ProtoOrIfaceArray, create_dom_global}',
- 'dom::bindings::utils::{enumerate_global, finalize_global, find_enum_string_index}',
- 'dom::bindings::utils::{generic_getter, generic_lenient_getter, generic_lenient_setter}',
- 'dom::bindings::utils::{generic_method, generic_setter, get_array_index_from_id}',
- 'dom::bindings::utils::{get_dictionary_property, get_property_on_prototype}',
- 'dom::bindings::utils::{get_proto_or_iface_array, has_property_on_prototype}',
- 'dom::bindings::utils::{is_platform_object, resolve_global, set_dictionary_property, trace_global}',
+ 'dom::bindings::utils::{ProtoOrIfaceArray, enumerate_global, finalize_global}',
+ 'dom::bindings::utils::{find_enum_string_index, generic_getter, generic_lenient_getter}',
+ 'dom::bindings::utils::{generic_lenient_setter, generic_method, generic_setter}',
+ 'dom::bindings::utils::{get_array_index_from_id, get_dictionary_property}',
+ 'dom::bindings::utils::{get_property_on_prototype, get_proto_or_iface_array}',
+ 'dom::bindings::utils::{has_property_on_prototype, is_platform_object}',
+ 'dom::bindings::utils::{resolve_global, set_dictionary_property, trace_global}',
'dom::bindings::trace::{JSTraceable, RootedTraceable}',
'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}',
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index 47a549602b6..bcc619579dc 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -6,23 +6,26 @@
use dom::bindings::codegen::InterfaceObjectMap::Globals;
use dom::bindings::codegen::PrototypeList;
-use dom::bindings::conversions::get_dom_class;
+use dom::bindings::conversions::{DOM_OBJECT_SLOT, get_dom_class};
use dom::bindings::guard::Guard;
-use dom::bindings::utils::get_proto_or_iface_array;
+use dom::bindings::utils::{DOM_PROTOTYPE_SLOT, ProtoOrIfaceArray, get_proto_or_iface_array};
use js::error::throw_type_error;
use js::glue::{RUST_SYMBOL_TO_JSID, UncheckedUnwrapObject};
-use js::jsapi::{Class, ClassOps, GetGlobalForObjectCrossCompartment};
-use js::jsapi::{GetWellKnownSymbol, HandleObject, HandleValue, JSClass, JSContext};
-use js::jsapi::{JSFunctionSpec, JSNative, JSFUN_CONSTRUCTOR, JSPROP_ENUMERATE};
-use js::jsapi::{JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING, JSPropertySpec};
-use js::jsapi::{JSString, JS_AtomizeAndPinString, JS_DefineProperty, JS_DefineProperty1};
-use js::jsapi::{JS_DefineProperty2, JS_DefineProperty4, JS_DefinePropertyById3};
-use js::jsapi::{JS_GetClass, JS_GetFunctionObject, JS_GetPrototype, JS_LinkConstructorAndPrototype};
-use js::jsapi::{JS_NewFunction, JS_NewObject, JS_NewObjectWithUniqueType};
-use js::jsapi::{JS_NewPlainObject, JS_NewStringCopyN, MutableHandleObject};
-use js::jsapi::{MutableHandleValue, ObjectOps};
-use js::jsapi::{SymbolCode, TrueHandleValue, Value};
-use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UInt32Value};
+use js::jsapi::{Class, ClassOps, CompartmentOptions, GetGlobalForObjectCrossCompartment};
+use js::jsapi::{GetWellKnownSymbol, HandleObject, HandleValue, JSAutoCompartment};
+use js::jsapi::{JSClass, JSContext, JSFUN_CONSTRUCTOR, JSFunctionSpec, JSNative, JSObject};
+use js::jsapi::{JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING};
+use js::jsapi::{JSPropertySpec, JSString, JSTracer, JSVersion, JS_AtomizeAndPinString};
+use js::jsapi::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2};
+use js::jsapi::{JS_DefineProperty4, JS_DefinePropertyById3, JS_FireOnNewGlobalObject};
+use js::jsapi::{JS_GetClass, JS_GetFunctionObject, JS_GetPrototype};
+use js::jsapi::{JS_LinkConstructorAndPrototype, JS_NewFunction, JS_NewGlobalObject};
+use js::jsapi::{JS_NewObject, JS_NewObjectWithUniqueType, JS_NewPlainObject};
+use js::jsapi::{JS_NewStringCopyN, JS_SetReservedSlot, MutableHandleObject};
+use js::jsapi::{MutableHandleValue, ObjectOps, OnNewGlobalHookOption, SymbolCode};
+use js::jsapi::{TrueHandleValue, Value};
+use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue};
+use js::jsval::{PrivateValue, UInt32Value};
use js::rust::{define_methods, define_properties};
use libc;
use std::ptr;
@@ -206,6 +209,46 @@ impl InterfaceConstructorBehavior {
}
}
+/// A trace hook.
+pub type TraceHook =
+ unsafe extern "C" fn(trc: *mut JSTracer, obj: *mut JSObject);
+
+/// Create a global object with the given class.
+pub unsafe fn create_global_object(
+ cx: *mut JSContext,
+ class: *const JSClass,
+ private: *const libc::c_void,
+ trace: TraceHook)
+ -> *mut JSObject {
+ let mut options = CompartmentOptions::default();
+ options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
+ options.creationOptions_.traceGlobal_ = Some(trace);
+ options.creationOptions_.sharedMemoryAndAtomics_ = true;
+
+ rooted!(in(cx) let obj =
+ JS_NewGlobalObject(cx,
+ class,
+ ptr::null_mut(),
+ OnNewGlobalHookOption::DontFireOnNewGlobalHook,
+ &options));
+ if obj.is_null() {
+ return ptr::null_mut();
+ }
+
+ // Initialize the reserved slots before doing anything that can GC, to
+ // avoid getting trace hooks called on a partially initialized object.
+ JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT, PrivateValue(private));
+ let proto_array: Box<ProtoOrIfaceArray> =
+ box [0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH];
+ JS_SetReservedSlot(obj.get(),
+ DOM_PROTOTYPE_SLOT,
+ PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
+
+ let _ac = JSAutoCompartment::new(cx, obj.get());
+ JS_FireOnNewGlobalObject(cx, obj.handle());
+ obj.get()
+}
+
/// Create and define the interface object of a callback interface.
pub unsafe fn create_callback_interface_object(
cx: *mut JSContext,
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 6b2856e7a9e..ac902a5d68c 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -7,8 +7,7 @@
use dom::bindings::codegen::InterfaceObjectMap;
use dom::bindings::codegen::PrototypeList;
use dom::bindings::codegen::PrototypeList::{MAX_PROTO_CHAIN_LENGTH, PROTO_OR_IFACE_LENGTH};
-use dom::bindings::conversions::{DOM_OBJECT_SLOT, is_dom_class};
-use dom::bindings::conversions::{jsstring_to_str, private_from_proto_check};
+use dom::bindings::conversions::{is_dom_class, jsstring_to_str, private_from_proto_check};
use dom::bindings::error::throw_invalid_this;
use dom::bindings::inheritance::TopTypeId;
use dom::bindings::str::DOMString;
@@ -21,20 +20,18 @@ use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper};
use js::glue::{GetCrossCompartmentWrapper, WrapperNew};
use js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING};
use js::glue::{RUST_JSID_TO_INT, RUST_JSID_TO_STRING, UnwrapObject};
-use js::jsapi::{CallArgs, CompartmentOptions, DOMCallbacks, GetGlobalForObjectCrossCompartment};
-use js::jsapi::{HandleId, HandleObject, HandleValue, Heap, JSAutoCompartment, JSClass, JSContext};
-use js::jsapi::{JSJitInfo, JSObject, JSTraceOp, JSTracer, JSVersion, JSWrapObjectCallbacks};
-use js::jsapi::{JS_DeletePropertyById, JS_EnumerateStandardClasses, JS_FireOnNewGlobalObject};
+use js::jsapi::{CallArgs, DOMCallbacks, GetGlobalForObjectCrossCompartment};
+use js::jsapi::{HandleId, HandleObject, HandleValue, Heap, JSAutoCompartment, JSContext};
+use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks};
+use js::jsapi::{JS_DeletePropertyById, JS_EnumerateStandardClasses};
use js::jsapi::{JS_ForwardGetPropertyTo, JS_GetClass, JS_GetLatin1StringCharsAndLength};
use js::jsapi::{JS_GetProperty, JS_GetPrototype, JS_GetReservedSlot, JS_HasProperty};
-use js::jsapi::{JS_HasPropertyById, JS_IsExceptionPending, JS_IsGlobalObject, JS_NewGlobalObject};
+use js::jsapi::{JS_HasPropertyById, JS_IsExceptionPending, JS_IsGlobalObject};
use js::jsapi::{JS_ResolveStandardClass, JS_SetProperty, ToWindowProxyIfWindow};
-use js::jsapi::{JS_SetReservedSlot, JS_StringHasLatin1Chars, MutableHandleValue};
-use js::jsapi::{ObjectOpResult, OnNewGlobalHookOption};
-use js::jsval::{JSVal, ObjectValue, PrivateValue, UndefinedValue};
+use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult};
+use js::jsval::{JSVal, ObjectValue, UndefinedValue};
use js::rust::{GCMethods, ToString};
use libc;
-use std::default::Default;
use std::ffi::CString;
use std::os::raw::c_void;
use std::ptr;
@@ -296,43 +293,6 @@ pub fn has_property_on_prototype(cx: *mut JSContext, proxy: HandleObject, id: Ha
}) || found
}
-/// Create a DOM global object with the given class.
-pub fn create_dom_global(cx: *mut JSContext,
- class: *const JSClass,
- private: *const libc::c_void,
- trace: JSTraceOp)
- -> *mut JSObject {
- unsafe {
- let mut options = CompartmentOptions::default();
- options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
- options.creationOptions_.traceGlobal_ = trace;
- options.creationOptions_.sharedMemoryAndAtomics_ = true;
-
- rooted!(in(cx) let obj =
- JS_NewGlobalObject(cx,
- class,
- ptr::null_mut(),
- OnNewGlobalHookOption::DontFireOnNewGlobalHook,
- &options));
- if obj.is_null() {
- return ptr::null_mut();
- }
-
- // Initialize the reserved slots before doing amything that can GC, to
- // avoid getting trace hooks called on a partially initialized object.
- JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT, PrivateValue(private));
- let proto_array: Box<ProtoOrIfaceArray> =
- box [0 as *mut JSObject; PROTO_OR_IFACE_LENGTH];
- JS_SetReservedSlot(obj.get(),
- DOM_PROTOTYPE_SLOT,
- PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
-
- let _ac = JSAutoCompartment::new(cx, obj.get());
- JS_FireOnNewGlobalObject(cx, obj.handle());
- obj.get()
- }
-}
-
/// Drop the resources held by reserved slots of a global object
pub unsafe fn finalize_global(obj: *mut JSObject) {
let protolist = get_proto_or_iface_array(obj);