Skip to content

Instantly share code, notes, and snippets.

@jdm
Created August 23, 2016 15:55
Show Gist options
  • Select an option

  • Save jdm/0c2fa6068c6f630a5377550f635cc2bb to your computer and use it in GitHub Desktop.

Select an option

Save jdm/0c2fa6068c6f630a5377550f635cc2bb to your computer and use it in GitHub Desktop.
--- before.rs 2016-08-23 11:52:12.000000000 -0400
+++ after.rs 2016-08-23 11:54:57.000000000 -0400
@@ -1,11 +1,11 @@
/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */
#![allow(non_camel_case_types,non_upper_case_globals,unused_imports,unused_variables,unused_assignments)]
+use dom;
use dom::bindings;
use dom::bindings::callback::wrap_call_this_object;
use dom::bindings::callback::{CallSetup,ExceptionHandling};
use dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction};
-use dom::bindings::codegen::Bindings::*;
use dom::bindings::codegen::InterfaceObjectMap;
use dom::bindings::codegen::{PrototypeList, RegisterBindings, UnionTypes};
use dom::bindings::conversions::{ConversionBehavior, DOM_OBJECT_SLOT};
@@ -26,6 +26,107 @@
use dom::bindings::interface::{create_callback_interface_object, create_interface_prototype_object};
use dom::bindings::interface::{create_named_constructors, create_noncallback_interface_object};
use dom::bindings::interface::{define_guarded_methods, define_guarded_properties};
+use dom::bindings::iterable::{IteratorType, Iterable};
+use dom::bindings::js::{JS, Root, RootedReference};
+use dom::bindings::js::{OptionalRootedReference};
+use dom::bindings::num::Finite;
+use dom::bindings::proxyhandler;
+use dom::bindings::proxyhandler::{ensure_expando_object, fill_property_descriptor};
+use dom::bindings::proxyhandler::{get_expando_object, get_property_descriptor};
+use dom::bindings::reflector::{Reflectable};
+use dom::bindings::str::{ByteString, DOMString, USVString};
+use dom::bindings::trace::{JSTraceable, RootedTraceable};
+use dom::bindings::utils::{DOMClass, DOMJSClass};
+use dom::bindings::utils::{DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, JSCLASS_DOM_GLOBAL};
+use dom::bindings::utils::{ProtoOrIfaceArray, create_dom_global};
+use dom::bindings::utils::{enumerate_global, finalize_global, find_enum_string_index};
+use dom::bindings::utils::{generic_getter, generic_lenient_getter, generic_lenient_setter};
+use dom::bindings::utils::{generic_method, generic_setter, get_array_index_from_id};
+use dom::bindings::utils::{get_dictionary_property, get_property_on_prototype};
+use dom::bindings::utils::{get_proto_or_iface_array, has_property_on_prototype};
+use dom::bindings::utils::{is_platform_object, resolve_global, set_dictionary_property, trace_global};
+use dom::bindings::weakref::{DOM_WEAK_SLOT, WeakBox, WeakReferenceable};
+use dom::browsingcontext::BrowsingContext;
+use js;
+use js::error::throw_type_error;
+use js::glue::AppendToAutoIdVector;
+use js::glue::{CallJitMethodOp, CallJitGetterOp, CallJitSetterOp, CreateProxyHandler};
+use js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps};
+use js::glue::{RUST_JSID_IS_STRING, int_to_jsid, RUST_SYMBOL_TO_JSID};
+use js::jsapi::{GetPropertyKeys, Handle, Call, GetWellKnownSymbol};
+use js::jsapi::{HandleId, HandleObject, HandleValue, HandleValueArray};
+use js::jsapi::{INTERNED_STRING_TO_JSID, IsCallable, JS_CallFunctionValue};
+use js::jsapi::{JSCLASS_RESERVED_SLOTS_SHIFT, JSITER_HIDDEN, JSITER_OWNONLY};
+use js::jsapi::{JSContext, JSClass, JSFreeOp, JSFunctionSpec, JS_GetIteratorPrototype};
+use js::jsapi::{JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_SHARED};
+use js::jsapi::{JSJitGetterCallArgs, JSJitInfo, JSJitMethodCallArgs, JSJitSetterCallArgs};
+use js::jsapi::{JSJitInfo_AliasSet, JSJitInfo_ArgType, AutoIdVector, CallArgs, FreeOp};
+use js::jsapi::{JSNative, JSObject, JSNativeWrapper, JSPropertySpec};
+use js::jsapi::{JSString, JSTracer, JSType, JSTypedMethodJitInfo, JSValueType};
+use js::jsapi::{JS_AtomizeAndPinString, JS_NewObject, JS_NewObjectWithGivenProto};
+use js::jsapi::{JS_CopyPropertiesFrom, JS_ForwardGetPropertyTo};
+use js::jsapi::{JS_GetClass, JS_GetErrorPrototype, JS_GetFunctionPrototype};
+use js::jsapi::{JS_GetGlobalForObject, JS_GetObjectPrototype, JS_GetProperty};
+use js::jsapi::{JS_GetPropertyById, JS_GetPropertyDescriptorById, JS_GetReservedSlot};
+use js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_InitializePropertiesFromCompatibleNativeObject};
+use js::jsapi::{JS_NewObjectWithoutMetadata, JS_SetProperty, JS_DefinePropertyById2};
+use js::jsapi::{JS_SetPrototype, JS_SetReservedSlot, JSAutoCompartment};
+use js::jsapi::{MutableHandleValue, PropertyDescriptor, RootedObject};
+use js::jsapi::{ObjectOpResult, JSJitInfo_OpType, MutableHandle, MutableHandleObject};
+use js::jsapi::{SymbolCode, jsid};
+use js::jsval::JSVal;
+use js::jsval::{NullValue, UndefinedValue};
+use js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue};
+use js::rust::{GCMethods, define_methods, define_properties};
+use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_MASK};
+use js::{JS_CALLEE, JSCLASS_GLOBAL_SLOT_COUNT};
+use libc;
+use mem::heap_size_of_raw_self_and_children;
+use script_runtime::{store_panic_result, maybe_take_panic_result};
+use std::borrow::ToOwned;
+use std::cmp;
+use std::default::Default;
+use std::ffi::CString;
+use std::mem;
+use std::num;
+use std::os;
+use std::panic::{self, AssertUnwindSafe};
+use std::ptr;
+use std::rc;
+use std::rc::Rc;
+use std::str;
+use util::prefs::PREFS;
+
+pub use self::TestBindingPairIterableBinding::{GetProtoObject as TestBindingPairIterableGetProtoObject, DefineDOMInterface as TestBindingPairIterableDefineDOMInterface, Wrap as TestBindingPairIterableWrap, TestBindingPairIterableMethods};
+pub mod TestBindingPairIterableBinding {
+#![allow(non_camel_case_types,non_upper_case_globals,unused_imports,unused_variables,unused_assignments)]
+use dom;
+use dom::bindings;
+use dom::bindings::callback::wrap_call_this_object;
+use dom::bindings::callback::{CallSetup,ExceptionHandling};
+use dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction};
+use dom::bindings::codegen::InterfaceObjectMap;
+use dom::bindings::codegen::{PrototypeList, RegisterBindings, UnionTypes};
+use dom::bindings::conversions::{ConversionBehavior, DOM_OBJECT_SLOT};
+use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior};
+use dom::bindings::conversions::{IDLInterface, is_array_like};
+use dom::bindings::conversions::{ToJSValConvertible, jsid_to_str, native_from_handlevalue};
+use dom::bindings::conversions::{native_from_object, private_from_object, root_from_object};
+use dom::bindings::conversions::{root_from_handleobject, root_from_handlevalue};
+use dom::bindings::error::Error::JSFailed;
+use dom::bindings::error::throw_dom_exception;
+use dom::bindings::error::{Fallible, Error, ErrorResult};
+use dom::bindings::global::{GlobalRef, global_root_from_object, global_root_from_reflector};
+use dom::bindings::guard::{Condition, Guard};
+use dom::bindings::interface::ConstantVal::{IntVal, UintVal};
+use dom::bindings::interface::is_exposed_in;
+use dom::bindings::interface::{ConstantSpec, NonNullJSNative};
+use dom::bindings::interface::{InterfaceConstructorBehavior, NonCallbackInterfaceObjectClass};
+use dom::bindings::interface::{create_callback_interface_object, create_interface_prototype_object};
+use dom::bindings::interface::{create_named_constructors, create_noncallback_interface_object};
+use dom::bindings::interface::{define_guarded_methods, define_guarded_properties};
+use dom::bindings::iterable::IterableIterator;
+use dom::bindings::iterable::{IteratorType, Iterable};
use dom::bindings::js::{JS, Root, RootedReference};
use dom::bindings::js::{OptionalRootedReference};
use dom::bindings::num::Finite;
@@ -52,12 +153,12 @@
use js::glue::AppendToAutoIdVector;
use js::glue::{CallJitMethodOp, CallJitGetterOp, CallJitSetterOp, CreateProxyHandler};
use js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps};
-use js::glue::{RUST_JSID_IS_STRING, int_to_jsid};
-use js::jsapi::{GetPropertyKeys, Handle};
+use js::glue::{RUST_JSID_IS_STRING, int_to_jsid, RUST_SYMBOL_TO_JSID};
+use js::jsapi::{GetPropertyKeys, Handle, Call, GetWellKnownSymbol};
use js::jsapi::{HandleId, HandleObject, HandleValue, HandleValueArray};
use js::jsapi::{INTERNED_STRING_TO_JSID, IsCallable, JS_CallFunctionValue};
use js::jsapi::{JSCLASS_RESERVED_SLOTS_SHIFT, JSITER_HIDDEN, JSITER_OWNONLY};
-use js::jsapi::{JSContext, JSClass, JSFreeOp, JSFunctionSpec};
+use js::jsapi::{JSContext, JSClass, JSFreeOp, JSFunctionSpec, JS_GetIteratorPrototype};
use js::jsapi::{JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_SHARED};
use js::jsapi::{JSJitGetterCallArgs, JSJitInfo, JSJitMethodCallArgs, JSJitSetterCallArgs};
use js::jsapi::{JSJitInfo_AliasSet, JSJitInfo_ArgType, AutoIdVector, CallArgs, FreeOp};
@@ -69,7 +170,7 @@
use js::jsapi::{JS_GetGlobalForObject, JS_GetObjectPrototype, JS_GetProperty};
use js::jsapi::{JS_GetPropertyById, JS_GetPropertyDescriptorById, JS_GetReservedSlot};
use js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_InitializePropertiesFromCompatibleNativeObject};
-use js::jsapi::{JS_NewObjectWithoutMetadata, JS_SetProperty};
+use js::jsapi::{JS_NewObjectWithoutMetadata, JS_SetProperty, JS_DefinePropertyById2};
use js::jsapi::{JS_SetPrototype, JS_SetReservedSlot, JSAutoCompartment};
use js::jsapi::{MutableHandleValue, PropertyDescriptor, RootedObject};
use js::jsapi::{ObjectOpResult, JSJitInfo_OpType, MutableHandle, MutableHandleObject};
@@ -97,7 +198,7 @@
use std::str;
use util::prefs::PREFS;
-fn GetProtoObject(cx: *mut JSContext, global: HandleObject, rval: MutableHandleObject) {
+pub fn GetProtoObject(cx: *mut JSContext, global: HandleObject, rval: MutableHandleObject) {
unsafe {
/* Get the interface prototype object for this class. This will create the
object as needed. */
@@ -169,6 +270,218 @@
)
};
+unsafe extern fn entries(cx: *mut JSContext, _obj: HandleObject, this: *const TestBindingPairIterable, args: *const JSJitMethodCallArgs) -> bool {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+ let this = &*this;
+ let args = &*args;
+ let argc = args._base.argc_;
+ let result = IterableIterator::new(&*this,
+ IteratorType::Entries,
+ super::TestBindingPairIterableIteratorBinding::Wrap);
+
+
+ (result).to_jsval(cx, args.rval());
+ return true;}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return false;
+ }
+ }
+
+}
+
+const entries_methodinfo_argTypes: [i32; 1] = [ JSJitInfo_ArgType::ArgTypeListEnd as i32 ];
+const entries_methodinfo: JSTypedMethodJitInfo = JSTypedMethodJitInfo {
+ base: JSJitInfo {
+ call: entries as *const os::raw::c_void,
+ protoID: PrototypeList::ID::TestBindingPairIterable as u16,
+ depth: 0,
+ _bitfield_1:
+ JSJitInfo::new_bitfield_1(
+ JSJitInfo_OpType::Method as u8,
+ JSJitInfo_AliasSet::AliasEverything as u8,
+ JSValueType::JSVAL_TYPE_OBJECT as u8,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ 0 as u16,
+ )
+ },
+ argTypes: &entries_methodinfo_argTypes as *const _ as *const JSJitInfo_ArgType,
+};
+
+unsafe extern fn keys(cx: *mut JSContext, _obj: HandleObject, this: *const TestBindingPairIterable, args: *const JSJitMethodCallArgs) -> bool {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+ let this = &*this;
+ let args = &*args;
+ let argc = args._base.argc_;
+ let result = IterableIterator::new(&*this,
+ IteratorType::Keys,
+ super::TestBindingPairIterableIteratorBinding::Wrap);
+
+
+ (result).to_jsval(cx, args.rval());
+ return true;}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return false;
+ }
+ }
+
+}
+
+const keys_methodinfo_argTypes: [i32; 1] = [ JSJitInfo_ArgType::ArgTypeListEnd as i32 ];
+const keys_methodinfo: JSTypedMethodJitInfo = JSTypedMethodJitInfo {
+ base: JSJitInfo {
+ call: keys as *const os::raw::c_void,
+ protoID: PrototypeList::ID::TestBindingPairIterable as u16,
+ depth: 0,
+ _bitfield_1:
+ JSJitInfo::new_bitfield_1(
+ JSJitInfo_OpType::Method as u8,
+ JSJitInfo_AliasSet::AliasEverything as u8,
+ JSValueType::JSVAL_TYPE_OBJECT as u8,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ 0 as u16,
+ )
+ },
+ argTypes: &keys_methodinfo_argTypes as *const _ as *const JSJitInfo_ArgType,
+};
+
+unsafe extern fn values(cx: *mut JSContext, _obj: HandleObject, this: *const TestBindingPairIterable, args: *const JSJitMethodCallArgs) -> bool {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+ let this = &*this;
+ let args = &*args;
+ let argc = args._base.argc_;
+ let result = IterableIterator::new(&*this,
+ IteratorType::Values,
+ super::TestBindingPairIterableIteratorBinding::Wrap);
+
+
+ (result).to_jsval(cx, args.rval());
+ return true;}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return false;
+ }
+ }
+
+}
+
+const values_methodinfo_argTypes: [i32; 1] = [ JSJitInfo_ArgType::ArgTypeListEnd as i32 ];
+const values_methodinfo: JSTypedMethodJitInfo = JSTypedMethodJitInfo {
+ base: JSJitInfo {
+ call: values as *const os::raw::c_void,
+ protoID: PrototypeList::ID::TestBindingPairIterable as u16,
+ depth: 0,
+ _bitfield_1:
+ JSJitInfo::new_bitfield_1(
+ JSJitInfo_OpType::Method as u8,
+ JSJitInfo_AliasSet::AliasEverything as u8,
+ JSValueType::JSVAL_TYPE_OBJECT as u8,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ 0 as u16,
+ )
+ },
+ argTypes: &values_methodinfo_argTypes as *const _ as *const JSJitInfo_ArgType,
+};
+
+unsafe extern fn forEach(cx: *mut JSContext, _obj: HandleObject, this: *const TestBindingPairIterable, args: *const JSJitMethodCallArgs) -> bool {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+ let this = &*this;
+ let args = &*args;
+ let argc = args._base.argc_;
+
+ if argc < 1 {
+ throw_type_error(cx, "Not enough arguments to \"TestBindingPairIterable.forEach\".");
+ return false;
+ }
+ let arg0: *mut JSObject = if args.get(0).get().is_object() {
+ args.get(0).get().to_object()
+ } else {
+ throw_type_error(cx, "Value is not an object.");
+ return false;
+ };
+ let arg1: HandleValue = if args.get(1).is_undefined() {
+ HandleValue::undefined()
+ } else {
+ args.get(1)
+ };
+ if !IsCallable(arg0) {
+ throw_type_error(cx, "Argument 1 of TestBindingPairIterable.forEach is not callable.");
+ return false;
+ }
+ rooted!(in(cx) let arg0 = ObjectValue(&*arg0));
+ rooted!(in(cx) let mut call_arg1 = UndefinedValue());
+ rooted!(in(cx) let mut call_arg2 = UndefinedValue());
+ let mut call_args = vec![UndefinedValue(), UndefinedValue(), ObjectValue(&**_obj)];
+ rooted!(in(cx) let mut ignoredReturnVal = UndefinedValue());
+ for i in 0..(*this).get_iterable_length() {
+ (*this).get_value_at_index(i).to_jsval(cx, call_arg1.handle_mut());
+ (*this).get_key_at_index(i).to_jsval(cx, call_arg2.handle_mut());
+ call_args[0] = call_arg1.handle().get();
+ call_args[1] = call_arg2.handle().get();
+ let call_args = HandleValueArray { length_: 3, elements_: call_args.as_ptr() };
+ if !Call(cx, arg1, arg0.handle(), &call_args,
+ ignoredReturnVal.handle_mut()) {
+ return false;
+ }
+ }
+
+ let result = ();
+
+
+ (result).to_jsval(cx, args.rval());
+ return true;}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return false;
+ }
+ }
+
+}
+
+
+const forEach_methodinfo: JSJitInfo = JSJitInfo {
+ call: forEach as *const os::raw::c_void,
+ protoID: PrototypeList::ID::TestBindingPairIterable as u16,
+ depth: 0,
+ _bitfield_1:
+ JSJitInfo::new_bitfield_1(
+ JSJitInfo_OpType::Method as u8,
+ JSJitInfo_AliasSet::AliasEverything as u8,
+ JSValueType::JSVAL_TYPE_UNDEFINED as u8,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ 0 as u16,
+ )
+};
+
unsafe extern fn _finalize(_fop: *mut FreeOp, obj: *mut JSObject) {
let result = panic::catch_unwind(AssertUnwindSafe(|| {
@@ -351,6 +664,34 @@
selfHostedName: 0 as *const libc::c_char
},
JSFunctionSpec {
+ name: b"entries\0" as *const u8 as *const libc::c_char,
+ call: JSNativeWrapper { op: Some(generic_method), info: &entries_methodinfo as *const _ as *const JSJitInfo },
+ nargs: 0,
+ flags: (JSPROP_ENUMERATE) as u16,
+ selfHostedName: 0 as *const libc::c_char
+ },
+ JSFunctionSpec {
+ name: b"keys\0" as *const u8 as *const libc::c_char,
+ call: JSNativeWrapper { op: Some(generic_method), info: &keys_methodinfo as *const _ as *const JSJitInfo },
+ nargs: 0,
+ flags: (JSPROP_ENUMERATE) as u16,
+ selfHostedName: 0 as *const libc::c_char
+ },
+ JSFunctionSpec {
+ name: b"values\0" as *const u8 as *const libc::c_char,
+ call: JSNativeWrapper { op: Some(generic_method), info: &values_methodinfo as *const _ as *const JSJitInfo },
+ nargs: 0,
+ flags: (JSPROP_ENUMERATE) as u16,
+ selfHostedName: 0 as *const libc::c_char
+ },
+ JSFunctionSpec {
+ name: b"forEach\0" as *const u8 as *const libc::c_char,
+ call: JSNativeWrapper { op: Some(generic_method), info: &forEach_methodinfo as *const _ as *const JSJitInfo },
+ nargs: 1,
+ flags: (JSPROP_ENUMERATE) as u16,
+ selfHostedName: 0 as *const libc::c_char
+ },
+ JSFunctionSpec {
name: 0 as *const libc::c_char,
call: JSNativeWrapper { op: None, info: 0 as *const JSJitInfo },
nargs: 0,
@@ -402,7 +743,356 @@
0,
interface.handle_mut());
assert!(!interface.is_null());
+ // Set up aliases on the interface prototype object we just created.
+
+ rooted!(in(cx) let mut aliasedVal = UndefinedValue());
+
+ assert!(JS_GetProperty(cx, prototype.handle(),
+ b"entries" as *const u8 as *const i8,
+ aliasedVal.handle_mut()));
+ rooted!(in(cx) let iteratorId = RUST_SYMBOL_TO_JSID(GetWellKnownSymbol(cx, SymbolCode::iterator)));
+ assert!(JS_DefinePropertyById2(cx, prototype.handle(), iteratorId.handle(), aliasedVal.handle(),
+ JSPROP_ENUMERATE, None, None));
+
+ }
+}
+} // mod TestBindingPairIterableBinding
+
+
+pub use self::TestBindingPairIterableIteratorBinding::{GetProtoObject as TestBindingPairIterableIteratorGetProtoObject, Wrap as TestBindingPairIterableIteratorWrap, TestBindingPairIterableIteratorMethods};
+pub mod TestBindingPairIterableIteratorBinding {
+#![allow(non_camel_case_types,non_upper_case_globals,unused_imports,unused_variables,unused_assignments)]
+use dom;
+use dom::bindings;
+use dom::bindings::callback::wrap_call_this_object;
+use dom::bindings::callback::{CallSetup,ExceptionHandling};
+use dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction};
+use dom::bindings::codegen::InterfaceObjectMap;
+use dom::bindings::codegen::{PrototypeList, RegisterBindings, UnionTypes};
+use dom::bindings::conversions::{ConversionBehavior, DOM_OBJECT_SLOT};
+use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior};
+use dom::bindings::conversions::{IDLInterface, is_array_like};
+use dom::bindings::conversions::{ToJSValConvertible, jsid_to_str, native_from_handlevalue};
+use dom::bindings::conversions::{native_from_object, private_from_object, root_from_object};
+use dom::bindings::conversions::{root_from_handleobject, root_from_handlevalue};
+use dom::bindings::error::Error::JSFailed;
+use dom::bindings::error::throw_dom_exception;
+use dom::bindings::error::{Fallible, Error, ErrorResult};
+use dom::bindings::global::{GlobalRef, global_root_from_object, global_root_from_reflector};
+use dom::bindings::guard::{Condition, Guard};
+use dom::bindings::interface::ConstantVal::{IntVal, UintVal};
+use dom::bindings::interface::is_exposed_in;
+use dom::bindings::interface::{ConstantSpec, NonNullJSNative};
+use dom::bindings::interface::{InterfaceConstructorBehavior, NonCallbackInterfaceObjectClass};
+use dom::bindings::interface::{create_callback_interface_object, create_interface_prototype_object};
+use dom::bindings::interface::{create_named_constructors, create_noncallback_interface_object};
+use dom::bindings::interface::{define_guarded_methods, define_guarded_properties};
+use dom::bindings::iterable::IterableIterator;
+use dom::bindings::iterable::{IteratorType, Iterable};
+use dom::bindings::js::{JS, Root, RootedReference};
+use dom::bindings::js::{OptionalRootedReference};
+use dom::bindings::num::Finite;
+use dom::bindings::proxyhandler;
+use dom::bindings::proxyhandler::{ensure_expando_object, fill_property_descriptor};
+use dom::bindings::proxyhandler::{get_expando_object, get_property_descriptor};
+use dom::bindings::reflector::{Reflectable};
+use dom::bindings::str::{ByteString, DOMString, USVString};
+use dom::bindings::trace::{JSTraceable, RootedTraceable};
+use dom::bindings::utils::{DOMClass, DOMJSClass};
+use dom::bindings::utils::{DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, JSCLASS_DOM_GLOBAL};
+use dom::bindings::utils::{ProtoOrIfaceArray, create_dom_global};
+use dom::bindings::utils::{enumerate_global, finalize_global, find_enum_string_index};
+use dom::bindings::utils::{generic_getter, generic_lenient_getter, generic_lenient_setter};
+use dom::bindings::utils::{generic_method, generic_setter, get_array_index_from_id};
+use dom::bindings::utils::{get_dictionary_property, get_property_on_prototype};
+use dom::bindings::utils::{get_proto_or_iface_array, has_property_on_prototype};
+use dom::bindings::utils::{is_platform_object, resolve_global, set_dictionary_property, trace_global};
+use dom::bindings::weakref::{DOM_WEAK_SLOT, WeakBox, WeakReferenceable};
+use dom::browsingcontext::BrowsingContext;
+use dom::types::TestBindingPairIterable;
+use js;
+use js::error::throw_type_error;
+use js::glue::AppendToAutoIdVector;
+use js::glue::{CallJitMethodOp, CallJitGetterOp, CallJitSetterOp, CreateProxyHandler};
+use js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps};
+use js::glue::{RUST_JSID_IS_STRING, int_to_jsid, RUST_SYMBOL_TO_JSID};
+use js::jsapi::{GetPropertyKeys, Handle, Call, GetWellKnownSymbol};
+use js::jsapi::{HandleId, HandleObject, HandleValue, HandleValueArray};
+use js::jsapi::{INTERNED_STRING_TO_JSID, IsCallable, JS_CallFunctionValue};
+use js::jsapi::{JSCLASS_RESERVED_SLOTS_SHIFT, JSITER_HIDDEN, JSITER_OWNONLY};
+use js::jsapi::{JSContext, JSClass, JSFreeOp, JSFunctionSpec, JS_GetIteratorPrototype};
+use js::jsapi::{JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_SHARED};
+use js::jsapi::{JSJitGetterCallArgs, JSJitInfo, JSJitMethodCallArgs, JSJitSetterCallArgs};
+use js::jsapi::{JSJitInfo_AliasSet, JSJitInfo_ArgType, AutoIdVector, CallArgs, FreeOp};
+use js::jsapi::{JSNative, JSObject, JSNativeWrapper, JSPropertySpec};
+use js::jsapi::{JSString, JSTracer, JSType, JSTypedMethodJitInfo, JSValueType};
+use js::jsapi::{JS_AtomizeAndPinString, JS_NewObject, JS_NewObjectWithGivenProto};
+use js::jsapi::{JS_CopyPropertiesFrom, JS_ForwardGetPropertyTo};
+use js::jsapi::{JS_GetClass, JS_GetErrorPrototype, JS_GetFunctionPrototype};
+use js::jsapi::{JS_GetGlobalForObject, JS_GetObjectPrototype, JS_GetProperty};
+use js::jsapi::{JS_GetPropertyById, JS_GetPropertyDescriptorById, JS_GetReservedSlot};
+use js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_InitializePropertiesFromCompatibleNativeObject};
+use js::jsapi::{JS_NewObjectWithoutMetadata, JS_SetProperty, JS_DefinePropertyById2};
+use js::jsapi::{JS_SetPrototype, JS_SetReservedSlot, JSAutoCompartment};
+use js::jsapi::{MutableHandleValue, PropertyDescriptor, RootedObject};
+use js::jsapi::{ObjectOpResult, JSJitInfo_OpType, MutableHandle, MutableHandleObject};
+use js::jsapi::{SymbolCode, jsid};
+use js::jsval::JSVal;
+use js::jsval::{NullValue, UndefinedValue};
+use js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue};
+use js::rust::{GCMethods, define_methods, define_properties};
+use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_MASK};
+use js::{JS_CALLEE, JSCLASS_GLOBAL_SLOT_COUNT};
+use libc;
+use mem::heap_size_of_raw_self_and_children;
+use script_runtime::{store_panic_result, maybe_take_panic_result};
+use std::borrow::ToOwned;
+use std::cmp;
+use std::default::Default;
+use std::ffi::CString;
+use std::mem;
+use std::num;
+use std::os;
+use std::panic::{self, AssertUnwindSafe};
+use std::ptr;
+use std::rc;
+use std::rc::Rc;
+use std::str;
+use util::prefs::PREFS;
+
+pub fn GetProtoObject(cx: *mut JSContext, global: HandleObject, rval: MutableHandleObject) {
+ unsafe {
+ /* Get the interface prototype object for this class. This will create the
+ object as needed. */
+ assert!(((*JS_GetClass(global.get())).flags & JSCLASS_DOM_GLOBAL) != 0);
+
+ /* Check to see whether the interface objects are already installed */
+ let proto_or_iface_array = get_proto_or_iface_array(global.get());
+ rval.set((*proto_or_iface_array)[PrototypeList::ID::TestBindingPairIterableIterator as usize]);
+ if !rval.get().is_null() {
+ return;
+ }
+
+ CreateInterfaceObjects(cx, global, proto_or_iface_array);
+ rval.set((*proto_or_iface_array)[PrototypeList::ID::TestBindingPairIterableIterator as usize]);
+ assert!(!rval.get().is_null());
+
+ }
+}
+
+unsafe extern fn next(cx: *mut JSContext, _obj: HandleObject, this: *const IterableIterator<TestBindingPairIterable>, args: *const JSJitMethodCallArgs) -> bool {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+ let this = &*this;
+ let args = &*args;
+ let argc = args._base.argc_;
+ let result: Result<*mut JSObject, Error> = this.Next(cx);
+ let result = match result {
+ Ok(result) => result,
+ Err(e) => {
+ let global = global_root_from_reflector(this);
+ throw_dom_exception(cx, global.r(), e);
+ return false;
+ },
+ };
+
+ (result).to_jsval(cx, args.rval());
+ return true;}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return false;
+ }
+ }
+
+}
+
+
+const next_methodinfo: JSJitInfo = JSJitInfo {
+ call: next as *const os::raw::c_void,
+ protoID: PrototypeList::ID::TestBindingPairIterableIterator as u16,
+ depth: 0,
+ _bitfield_1:
+ JSJitInfo::new_bitfield_1(
+ JSJitInfo_OpType::Method as u8,
+ JSJitInfo_AliasSet::AliasEverything as u8,
+ JSValueType::JSVAL_TYPE_OBJECT as u8,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ 0 as u16,
+ )
+};
+
+unsafe extern fn _finalize(_fop: *mut FreeOp, obj: *mut JSObject) {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+
+ let this = native_from_object::<IterableIterator<TestBindingPairIterable>>(obj).unwrap();
+ if !this.is_null() {
+ // The pointer can be null if the object is the unforgeable holder of that interface.
+ let _ = Box::from_raw(this as *mut IterableIterator<TestBindingPairIterable>);
+ }
+ debug!("IterableIterator<TestBindingPairIterable> finalize: {:p}", this);}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return;
+ }
+ }
+
+}
+
+unsafe extern fn _trace(trc: *mut JSTracer, obj: *mut JSObject) {
+ let result = panic::catch_unwind(AssertUnwindSafe(|| {
+
+ let this = native_from_object::<IterableIterator<TestBindingPairIterable>>(obj).unwrap();
+ if this.is_null() { return; } // GC during obj creation
+ (*this).trace(trc);}));
+ match result {
+ Ok(result) => result,
+ Err(error) => {
+ store_panic_result(error);
+ return;
+ }
+ }
+
+}
+
+static PrototypeClass: JSClass = JSClass {
+ name: b"TestBindingPairIterableIteratorPrototype\0" as *const u8 as *const libc::c_char,
+ flags:
+ // JSCLASS_HAS_RESERVED_SLOTS(0)
+ (0 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT,
+ cOps: 0 as *const _,
+ reserved: [0 as *mut os::raw::c_void; 3]
+};
+
+static CLASS_OPS: js::jsapi::ClassOps = js::jsapi::ClassOps {
+ addProperty: None,
+ delProperty: None,
+ getProperty: None,
+ setProperty: None,
+ enumerate: None,
+ resolve: None,
+ mayResolve: None,
+ finalize: Some(_finalize),
+ call: None,
+ hasInstance: None,
+ construct: None,
+ trace: Some(_trace),
+};
+
+static Class: DOMJSClass = DOMJSClass {
+ base: js::jsapi::Class {
+ name: b"TestBindingPairIterableIterator\0" as *const u8 as *const libc::c_char,
+ flags: JSCLASS_IS_DOMJSCLASS | 0 |
+ (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
+ /* JSCLASS_HAS_RESERVED_SLOTS(1) */,
+ cOps: &CLASS_OPS,
+ spec: ptr::null(),
+ ext: ptr::null(),
+ oOps: ptr::null(),
+ },
+ dom_class: DOMClass {
+ interface_chain: [ PrototypeList::ID::TestBindingPairIterableIterator, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
+ type_id: ::dom::bindings::codegen::InheritTypes::TopTypeId::Alone,
+ heap_size_of: heap_size_of_raw_self_and_children::<IterableIterator<TestBindingPairIterable>> as unsafe fn(_) -> _,
+ global: InterfaceObjectMap::EMPTY,
+}
+};
+pub fn Wrap(cx: *mut JSContext, scope: GlobalRef, object: Box<IterableIterator<TestBindingPairIterable>>) -> Root<IterableIterator<TestBindingPairIterable>> {
+ unsafe {
+ let scope = scope.reflector().get_jsobject();
+ assert!(!scope.get().is_null());
+ assert!(((*JS_GetClass(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
+
+ rooted!(in(cx) let mut proto = ptr::null_mut());
+ let _ac = JSAutoCompartment::new(cx, scope.get());
+ GetProtoObject(cx, scope, proto.handle_mut());
+ assert!(!proto.is_null());
+
+ let raw = Box::into_raw(object);
+ let _rt = RootedTraceable::new(&*raw);
+ rooted!(in(cx) let obj = JS_NewObjectWithGivenProto(
+ cx, &Class.base as *const js::jsapi::Class as *const JSClass, proto.handle()));
+ assert!(!obj.is_null());
+
+ JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT,
+ PrivateValue(raw as *const libc::c_void));
+
+
+ (*raw).init_reflector(obj.get());
+
+ Root::from_ref(&*raw)
+ }
+}
+
+impl IDLInterface for IterableIterator<TestBindingPairIterable> {
+ #[inline]
+ fn derives(class: &'static DOMClass) -> bool {
+ class as *const _ == &Class.dom_class as *const _
+ }
+}
+
+impl PartialEq for IterableIterator<TestBindingPairIterable> {
+ fn eq(&self, other: &IterableIterator<TestBindingPairIterable>) -> bool {
+ self as *const IterableIterator<TestBindingPairIterable> == &*other
+ }
+}
+
+pub trait TestBindingPairIterableIteratorMethods {
+ fn Next(&self, cx: *mut JSContext) -> Fallible<*mut JSObject>;
+}
+const sMethods_specs: &'static [&'static[JSFunctionSpec]] = &[
+&[
+ JSFunctionSpec {
+ name: b"next\0" as *const u8 as *const libc::c_char,
+ call: JSNativeWrapper { op: Some(generic_method), info: &next_methodinfo as *const _ as *const JSJitInfo },
+ nargs: 0,
+ flags: (JSPROP_ENUMERATE) as u16,
+ selfHostedName: 0 as *const libc::c_char
+ },
+ JSFunctionSpec {
+ name: 0 as *const libc::c_char,
+ call: JSNativeWrapper { op: None, info: 0 as *const JSJitInfo },
+ nargs: 0,
+ flags: 0,
+ selfHostedName: 0 as *const libc::c_char
+ }]
+
+];
+const sMethods: &'static [Guard<&'static [JSFunctionSpec]>] = &[
+ Guard::new(Condition::Satisfied, sMethods_specs[0])
+];
+
+fn CreateInterfaceObjects(cx: *mut JSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray) {
+ unsafe {
+ rooted!(in(cx) let mut prototype_proto = ptr::null_mut());
+ prototype_proto.set(JS_GetIteratorPrototype(cx));
+ assert!(!prototype_proto.is_null());
+
+ rooted!(in(cx) let mut prototype = ptr::null_mut());
+ create_interface_prototype_object(cx,
+ prototype_proto.handle(),
+ &PrototypeClass,
+ sMethods,
+ &[],
+ &[],
+ &[],
+ prototype.handle_mut());
+ assert!(!prototype.is_null());
+ assert!((*cache)[PrototypeList::ID::TestBindingPairIterableIterator as usize].is_null());
+ (*cache)[PrototypeList::ID::TestBindingPairIterableIterator as usize] = prototype.get();
+ <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::TestBindingPairIterableIterator as isize),
+ ptr::null_mut(),
+ prototype.get());
+
}
}
+} // mod TestBindingPairIterableIteratorBinding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment