@@ -63,13 +63,12 @@ use ipc_channel::ipc::IpcSender;
6363use ipc_channel:: router:: ROUTER ;
6464use js:: jsapi:: JSAutoCompartment ;
6565use js:: jsapi:: JSContext ;
66- use js:: jsval :: JSObject ;
66+ use js:: jsapi :: JSObject ;
6767use js:: jsapi:: JSPROP_ENUMERATE ;
68- use js:: jsapi:: JS_GetRuntime ;
6968use js:: jsapi:: JS_GC ;
7069use js:: jsval:: JSVal ;
7170use js:: jsval:: UndefinedValue ;
72- use js:: rust:: HandleValue ;
71+ use js:: rust:: { HandleValue , HandleObject , MutableHandleObject } ;
7372use js:: rust:: wrappers:: JS_DefineProperty ;
7473use layout_image:: fetch_image_for_layout;
7574use libc;
@@ -136,6 +135,7 @@ use task_source::websocket::WebsocketTaskSource;
136135use time;
137136use timers:: { IsInterval , TimerCallback } ;
138137use url:: Position ;
138+ use window_named_properties;
139139use webdriver_handlers:: jsval_to_webdriver;
140140use webrender_api:: { ExternalScrollId , DeviceIntPoint , DeviceUintSize , DocumentId } ;
141141use webvr_traits:: WebVRMsg ;
@@ -1005,63 +1005,6 @@ impl WindowMethods for Window {
10051005 )
10061006 }
10071007
1008- // https://heycam.github.io/webidl/#named-properties-object
1009- // https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
1010- #[ allow( unsafe_code) ]
1011- unsafe fn CreateNamedPropertiesObject ( _cx : * mut JSContext , _proto : MutableHandleObject ) {
1012- unimplemented ! ( "Wow!" )
1013- }
1014-
1015- // https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
1016- fn SupportedPropertyNames ( & self ) -> Vec < DOMString > {
1017- // FIXME: unimplemented (https://github.com/servo/servo/issues/7273).
1018- //
1019- // See also Document::SupportedPropertyNames.
1020- vec ! [ ]
1021- }
1022-
1023- #[ allow( unsafe_code) ]
1024- // https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
1025- unsafe fn NamedGetter (
1026- & self ,
1027- cx : * mut JSContext ,
1028- name : DOMString ,
1029- ) -> Option < NonNull < JSObject > > {
1030- // TODO: Return child windows, like iframes and such. When this is
1031- // fixed, please implement IndexedGetter properly too.
1032- let document = self . Document ( ) ;
1033- if !document. is_html_document ( ) {
1034- return None ;
1035- }
1036-
1037- // TODO(emilio): There is a missing fast-path here for when we know
1038- // there aren't any named items with a given `name`. In that case, we
1039- // can return `document.get_element_by_id(name)` (unless there are many
1040- // of those elements), which is much faster.
1041- let name = Atom :: from ( name) ;
1042-
1043- let filter = WindowNamedGetterFilter { name } ;
1044-
1045- let root = document. upcast ( ) ;
1046- {
1047- let mut named_elements = document. upcast :: < Node > ( )
1048- . traverse_preorder ( )
1049- . filter_map ( DomRoot :: downcast :: < Element > )
1050- . filter ( |element| filter. filter ( & element, & root) ) ;
1051-
1052- let first_element = named_elements. next ( ) ?;
1053- if named_elements. next ( ) . is_none ( ) {
1054- return Some ( NonNull :: new_unchecked (
1055- first_element. reflector ( ) . get_jsobject ( ) . get ( )
1056- ) ) ;
1057- }
1058- }
1059-
1060- let collection =
1061- HTMLCollection :: create ( self , root, Box :: new ( filter) ) ;
1062- Some ( NonNull :: new_unchecked ( collection. reflector ( ) . get_jsobject ( ) . get ( ) ) )
1063- }
1064-
10651008 // https://drafts.csswg.org/cssom-view/#dom-window-innerheight
10661009 //TODO Include Scrollbar
10671010 fn InnerHeight ( & self ) -> i32 {
@@ -1270,6 +1213,67 @@ impl WindowMethods for Window {
12701213}
12711214
12721215impl Window {
1216+ // https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
1217+ fn SupportedPropertyNames ( & self ) -> Vec < DOMString > {
1218+ // FIXME: unimplemented (https://github.com/servo/servo/issues/7273).
1219+ //
1220+ // See also Document::SupportedPropertyNames.
1221+ vec ! [ ]
1222+ }
1223+
1224+ #[ allow( unsafe_code) ]
1225+ // https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
1226+ pub unsafe fn NamedGetter (
1227+ & self ,
1228+ cx : * mut JSContext ,
1229+ name : DOMString ,
1230+ ) -> Option < NonNull < JSObject > > {
1231+ // TODO: Return child windows, like iframes and such. When this is
1232+ // fixed, please implement IndexedGetter properly too.
1233+ let document = self . Document ( ) ;
1234+ if !document. is_html_document ( ) {
1235+ return None ;
1236+ }
1237+
1238+ // TODO(emilio): There is a missing fast-path here for when we know
1239+ // there aren't any named items with a given `name`. In that case, we
1240+ // can return `document.get_element_by_id(name)` (unless there are many
1241+ // of those elements), which is much faster.
1242+ let name = Atom :: from ( name) ;
1243+
1244+ let filter = WindowNamedGetterFilter { name } ;
1245+
1246+ let root = document. upcast ( ) ;
1247+ {
1248+ let mut named_elements = document. upcast :: < Node > ( )
1249+ . traverse_preorder ( )
1250+ . filter_map ( DomRoot :: downcast :: < Element > )
1251+ . filter ( |element| filter. filter ( & element, & root) ) ;
1252+
1253+ let first_element = named_elements. next ( ) ?;
1254+ if named_elements. next ( ) . is_none ( ) {
1255+ return Some ( NonNull :: new_unchecked (
1256+ first_element. reflector ( ) . get_jsobject ( ) . get ( )
1257+ ) ) ;
1258+ }
1259+ }
1260+
1261+ let collection =
1262+ HTMLCollection :: create ( self , root, Box :: new ( filter) ) ;
1263+ Some ( NonNull :: new_unchecked ( collection. reflector ( ) . get_jsobject ( ) . get ( ) ) )
1264+ }
1265+
1266+ // https://heycam.github.io/webidl/#named-properties-object
1267+ // https://html.spec.whatwg.org/multipage/#named-access-on-the-window-object
1268+ #[ allow( unsafe_code) ]
1269+ pub unsafe fn create_named_properties_object (
1270+ cx : * mut JSContext ,
1271+ proto : HandleObject ,
1272+ object : MutableHandleObject
1273+ ) {
1274+ window_named_properties:: create ( cx, proto, object)
1275+ }
1276+
12731277 // https://drafts.css-houdini.org/css-paint-api-1/#paint-worklet
12741278 pub fn paint_worklet ( & self ) -> DomRoot < Worklet > {
12751279 self . paint_worklet . or_init ( || self . new_paint_worklet ( ) )
0 commit comments