Title: [196583] trunk/Source/WebCore
Revision
196583
Author
[email protected]
Date
2016-02-15 11:56:18 -0800 (Mon, 15 Feb 2016)

Log Message

Organize, deduplicate & comment JSDOMWindowCustom getOwnPropertySlot
https://bugs.webkit.org/show_bug.cgi?id=154224

Reviewed by Chris Dumez.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::jsDOMWindowGetOwnPropertySlotRestrictedAccess):
(WebCore::jsDOMWindowGetOwnPropertySlotNamedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
    - organized property access sequence into a more logical order, removed
      duplicated code & added comments.
(WebCore::namedItemGetter): Deleted.
    - there was no need for a custom callback here; merged functionality into
      jsDOMWindowGetOwnPropertySlotNamedItemGetter.
(WebCore::jsDOMWindowGetOwnPropertySlotCrossOrigin): Deleted.
    - renamed to jsDOMWindowGetOwnPropertySlotRestrictedAccess
      (this now also handles frameless access).

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (196582 => 196583)


--- trunk/Source/WebCore/ChangeLog	2016-02-15 18:54:30 UTC (rev 196582)
+++ trunk/Source/WebCore/ChangeLog	2016-02-15 19:56:18 UTC (rev 196583)
@@ -1,3 +1,24 @@
+2016-02-14  Gavin Barraclough  <[email protected]>
+
+        Organize, deduplicate & comment JSDOMWindowCustom getOwnPropertySlot
+        https://bugs.webkit.org/show_bug.cgi?id=154224
+
+        Reviewed by Chris Dumez.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::jsDOMWindowGetOwnPropertySlotRestrictedAccess):
+        (WebCore::jsDOMWindowGetOwnPropertySlotNamedItemGetter):
+        (WebCore::JSDOMWindow::getOwnPropertySlot):
+        (WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
+            - organized property access sequence into a more logical order, removed
+              duplicated code & added comments.
+        (WebCore::namedItemGetter): Deleted.
+            - there was no need for a custom callback here; merged functionality into
+              jsDOMWindowGetOwnPropertySlotNamedItemGetter.
+        (WebCore::jsDOMWindowGetOwnPropertySlotCrossOrigin): Deleted.
+            - renamed to jsDOMWindowGetOwnPropertySlotRestrictedAccess
+              (this now also handles frameless access).
+
 2016-02-15  Daniel Bates  <[email protected]>
 
         CSP: 'sandbox' should be ignored in report-only mode

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (196582 => 196583)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp	2016-02-15 18:54:30 UTC (rev 196582)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp	2016-02-15 19:56:18 UTC (rev 196583)
@@ -66,27 +66,6 @@
         visitor.addOpaqueRoot(frame);
 }
 
-static EncodedJSValue namedItemGetter(ExecState* exec, EncodedJSValue thisValue, PropertyName propertyName)
-{
-    JSDOMWindowBase* thisObj = jsCast<JSDOMWindow*>(JSValue::decode(thisValue));
-    Document* document = thisObj->wrapped().frame()->document();
-
-    ASSERT(BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObj->wrapped()));
-    ASSERT(is<HTMLDocument>(document));
-
-    AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-    if (!atomicPropertyName || !downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName))
-        return JSValue::encode(jsUndefined());
-
-    if (UNLIKELY(downcast<HTMLDocument>(*document).windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
-        Ref<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
-        ASSERT(collection->length() > 1);
-        return JSValue::encode(toJS(exec, thisObj->globalObject(), WTF::getPtr(collection)));
-    }
-
-    return JSValue::encode(toJS(exec, thisObj->globalObject(), downcast<HTMLDocument>(*document).windowNamedItem(*atomicPropertyName)));
-}
-
 #if ENABLE(USER_MESSAGE_HANDLERS)
 static EncodedJSValue jsDOMWindowWebKit(ExecState* exec, EncodedJSValue thisValue, PropertyName)
 {
@@ -112,8 +91,34 @@
 }
 #endif
 
-static bool jsDOMWindowGetOwnPropertySlotCrossOrigin(JSDOMWindow* thisObject, ExecState* exec, PropertyName propertyName, PropertySlot& slot, String& errorMessage)
+static bool jsDOMWindowGetOwnPropertySlotRestrictedAccess(JSDOMWindow* thisObject, Frame* frame, ExecState* exec, PropertyName propertyName, PropertySlot& slot, String& errorMessage)
 {
+    // Allow access to toString() cross-domain, but always Object.prototype.toString.
+    if (propertyName == exec->propertyNames().toString) {
+        slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<objectProtoFuncToString, 0>);
+        return true;
+    }
+
+    // We don't want any properties other than "close" and "closed" on a frameless window
+    // (i.e. one whose page got closed, or whose iframe got removed).
+    // FIXME: This handling for frameless windows duplicates similar behaviour for cross-origin
+    // access below; we should try to find a way to merge the two.
+    if (!frame) {
+        if (propertyName == exec->propertyNames().closed) {
+            slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, jsDOMWindowClosed);
+            return true;
+        }
+        if (propertyName == exec->propertyNames().close) {
+            slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>);
+            return true;
+        }
+
+        // FIXME: We should have a message here that explains why the property access/function call was
+        // not allowed. 
+        slot.setUndefined();
+        return true;
+    }
+
     // These are the functions we allow access to cross-origin (DoNotCheckSecurity in IDL).
     // Always provide the original function, on a fresh uncached function object.
     if (propertyName == exec->propertyNames().blur) {
@@ -133,12 +138,6 @@
         return true;
     }
 
-    // Allow access to toString() cross-domain, but always Object.prototype.toString.
-    if (propertyName == exec->propertyNames().toString) {
-        slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<objectProtoFuncToString, 0>);
-        return true;
-    }
-
     // When accessing cross-origin known Window properties, we always use the original property getter,
     // even if the property was removed / redefined. As of early 2016, this matches Firefox and Chrome's
     // behavior.
@@ -177,129 +176,130 @@
         return true;
     }
 
-#if ENABLE(USER_MESSAGE_HANDLERS)
-    if (propertyName == exec->propertyNames().webkit && thisObject->wrapped().shouldHaveWebKitNamespaceForWorld(thisObject->world())) {
-        slot.setCacheableCustom(thisObject, ReadOnly | DontDelete | DontEnum, jsDOMWindowWebKit);
-        return true;
-    }
-#endif
-
-    // After this point it is no longer valid to cache any results because of
-    // the impure nature of the property accesses which follow. We can move this 
-    // statement further down when we add ways to mitigate these impurities with, 
-    // for example, watchpoints.
-    slot.disableCaching();
-
-    // Check for child frames by name before built-in properties to
-    // match Mozilla. This does not match IE, but some sites end up
-    // naming frames things that conflict with window properties that
-    // are in Moz but not IE. Since we have some of these, we have to do
-    // it the Moz way.
-    if (auto* scopedChild = thisObject->wrapped().frame()->tree().scopedChild(propertyNameToAtomicString(propertyName))) {
+    // Check for child frames by name before built-in properties to match Mozilla. This does
+    // not match IE, but some sites end up naming frames things that conflict with window
+    // properties that are in Moz but not IE. Since we have some of these, we have to do it
+    // the Moz way.
+    if (auto* scopedChild = frame->tree().scopedChild(propertyNameToAtomicString(propertyName))) {
         slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, toJS(exec, scopedChild->document()->domWindow()));
         return true;
     }
 
-    // allow window[1] or parent[1] etc. (#56983)
-    Optional<uint32_t> index = parseIndex(propertyName);
-    if (index && index.value() < thisObject->wrapped().frame()->tree().scopedChildCount()) {
-        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum,
-            toJS(exec, thisObject->wrapped().frame()->tree().scopedChild(index.value())->document()->domWindow()));
-        return true;
-    }
-
     thisObject->printErrorMessage(errorMessage);
     slot.setUndefined();
     return true;
 }
 
-bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
+static bool jsDOMWindowGetOwnPropertySlotNamedItemGetter(JSDOMWindow* thisObject, Frame& frame, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
 {
-    JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
-    // When accessing a Window cross-domain, functions are always the native built-in ones, and they
-    // are not affected by properties changed on the Window or anything in its prototype chain.
-    // This is consistent with the behavior of Firefox.
+    // FIXME: If the property is present on the prototype we should 'return false;', not
+    // return the property. This is supposed to be an 'own' access.
+    JSValue proto = thisObject->prototype();
+    if (proto.isObject() && asObject(proto)->getPropertySlot(exec, propertyName, slot))
+        return true;
 
-    // We don't want any properties other than "close" and "closed" on a frameless window (i.e. one whose page got closed,
-    // or whose iframe got removed).
-    // FIXME: This doesn't fully match Firefox, which allows at least toString in addition to those.
-    if (!thisObject->wrapped().frame()) {
-        // The following code is safe for cross-domain and same domain use.
-        // It ignores any custom properties that might be set on the DOMWindow (including a custom prototype).
-        if (propertyName == exec->propertyNames().closed) {
-            slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, jsDOMWindowClosed);
+    // Check for child frames by name before built-in properties to match Mozilla. This does
+    // not match IE, but some sites end up naming frames things that conflict with window
+    // properties that are in Moz but not IE. Since we have some of these, we have to do it
+    // the Moz way.
+    if (auto* scopedChild = frame.tree().scopedChild(propertyNameToAtomicString(propertyName))) {
+        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, toJS(exec, scopedChild->document()->domWindow()));
+        return true;
+    }
+
+    // FIXME: Search the whole frame hierarchy somewhere around here.
+    // We need to test the correct priority order.
+
+    // Allow shortcuts like 'Image1' instead of document.images.Image1
+    Document* document = frame.document();
+    if (is<HTMLDocument>(*document)) {
+        auto& htmlDocument = downcast<HTMLDocument>(*document);
+        auto* atomicPropertyName = propertyName.publicName();
+        if (atomicPropertyName && htmlDocument.hasWindowNamedItem(*atomicPropertyName)) {
+            JSValue namedItem;
+            if (UNLIKELY(htmlDocument.windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
+                Ref<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
+                ASSERT(collection->length() > 1);
+                namedItem = toJS(exec, thisObject->globalObject(), collection.ptr());
+            } else
+                namedItem = toJS(exec, thisObject->globalObject(), htmlDocument.windowNamedItem(*atomicPropertyName));
+            slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, namedItem);
             return true;
         }
-        if (propertyName == exec->propertyNames().close) {
-            slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>);
-            return true;
-        }
-
-        // FIXME: We should have a message here that explains why the property access/function call was
-        // not allowed. 
-        slot.setUndefined();
-        return true;
     }
 
-    slot.setWatchpointSet(thisObject->m_windowCloseWatchpoints);
+    return false;
+}
 
-    // We need to check for cross-domain access here without printing the generic warning message
-    // because we always allow access to some function, just different ones depending whether access
-    // is allowed.
+// Property access sequence is:
+// (1) indexed properties,
+// (2) regular own properties,
+// (3) named properties (in fact, these shouldn't be on the window, should be on the NPO).
+bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
+{
+    // (1) First, indexed properties.
+    // Hand off all indexed access to getOwnPropertySlotByIndex, which supports the indexed getter.
+    if (Optional<unsigned> index = parseIndex(propertyName))
+        return getOwnPropertySlotByIndex(object, exec, index.value(), slot);
+
+    auto* thisObject = jsCast<JSDOMWindow*>(object);
+    auto* frame = thisObject->wrapped().frame();
+
+    // Hand off all cross-domain/frameless access to jsDOMWindowGetOwnPropertySlotRestrictedAccess.
     String errorMessage;
-    if (!shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), errorMessage))
-        return jsDOMWindowGetOwnPropertySlotCrossOrigin(thisObject, exec, propertyName, slot, errorMessage);
+    if (!frame || !shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), errorMessage))
+        return jsDOMWindowGetOwnPropertySlotRestrictedAccess(thisObject, frame, exec, propertyName, slot, errorMessage);
     
-    // Look for overrides before looking at any of our own properties, but ignore overrides completely
-    // if this is cross-domain access.
-    if (JSGlobalObject::getOwnPropertySlot(thisObject, exec, propertyName, slot))
+    // FIXME: this need more explanation.
+    // (Particularly, is it correct that this exists here but not in getOwnPropertySlotByIndex?)
+    slot.setWatchpointSet(thisObject->m_windowCloseWatchpoints);
+
+    // (2) Regular own properties.
+    // FIXME: we should probably be able to use getStaticPropertySlot here.
+    if (Base::getOwnPropertySlot(thisObject, exec, propertyName, slot))
         return true;
-    
-    // We need this code here because otherwise JSDOMWindowBase will stop the search before we even get to the
-    // prototype due to the blanket same origin (shouldAllowAccessToDOMWindow) check at the end of getOwnPropertySlot.
-    // Also, it's important to get the implementation straight out of the DOMWindow prototype regardless of
-    // what prototype is actually set on this object.
+    if (!thisObject->staticFunctionsReified()) {
+        if (auto* entry = JSDOMWindow::info()->staticPropHashTable->entry(propertyName)) {
+            slot.setCacheableCustom(thisObject, entry->attributes(), entry->propertyGetter());
+            return true;
+        }
+    }
+    // FIXME: These are all bogus. Keeping these here make some tests pass that check these properties
+    // are own properties of the window, but introduces other problems instead (e.g. if you overwrite
+    // & delete then the original value is restored!) Should be removed.
     if (propertyName == exec->propertyNames().blur) {
         slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionBlur, 0>);
         return true;
-    } else if (propertyName == exec->propertyNames().close) {
+    }
+    if (propertyName == exec->propertyNames().close) {
         slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>);
         return true;
-    } else if (propertyName == exec->propertyNames().focus) {
+    }
+    if (propertyName == exec->propertyNames().focus) {
         slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionFocus, 0>);
         return true;
-    } else if (propertyName == exec->propertyNames().postMessage) {
+    }
+    if (propertyName == exec->propertyNames().postMessage) {
         slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionPostMessage, 2>);
         return true;
-    } else if (propertyName == exec->propertyNames().showModalDialog) {
-        if (!DOMWindow::canShowModalDialog(thisObject->wrapped().frame())) {
-            slot.setUndefined();
-            return true;
-        }
     }
-
+    // FIXME: this looks pretty bogus. It seems highly likely that if !canShowModalDialog the
+    // funtion should still be present, or should be omitted entirely - present but reads as
+    // undefined with unspecified attributes is likely wrong.
+    if (propertyName == exec->propertyNames().showModalDialog && !DOMWindow::canShowModalDialog(frame)) {
+        slot.setUndefined();
+        return true;
+    }
 #if ENABLE(INDEXED_DATABASE)
     // FIXME: With generated JS bindings built on static property tables there is no way to
-    // completely remove a generated property at runtime.
-    // So to completely disable IndexedDB at runtime we have to not generate these accessors
-    // and have to handle them specially here.
+    // completely remove a generated property at runtime. So to completely disable IndexedDB
+    // at runtime we have to not generate these accessors and have to handle them specially here.
     // Once https://webkit.org/b/145669 is resolved, they can once again be auto generated.
     if (RuntimeEnabledFeatures::sharedFeatures().indexedDBEnabled() && (propertyName == exec->propertyNames().indexedDB || propertyName == exec->propertyNames().webkitIndexedDB)) {
         slot.setCustom(thisObject, DontDelete | ReadOnly | CustomAccessor, jsDOMWindowIndexedDB);
         return true;
     }
 #endif
-
-    // When accessing cross-origin known Window properties, we always use the original property getter,
-    // even if the property was removed / redefined. As of early 2016, this matches Firefox and Chrome's
-    // behavior.
-    if (!thisObject->staticFunctionsReified()) {
-        if (auto* entry = JSDOMWindow::info()->staticPropHashTable->entry(propertyName)) {
-            slot.setCacheableCustom(thisObject, entry->attributes(), entry->propertyGetter());
-            return true;
-        }
-    }
-
 #if ENABLE(USER_MESSAGE_HANDLERS)
     if (propertyName == exec->propertyNames().webkit && thisObject->wrapped().shouldHaveWebKitNamespaceForWorld(thisObject->world())) {
         slot.setCacheableCustom(thisObject, DontDelete | ReadOnly, jsDOMWindowWebKit);
@@ -307,119 +307,42 @@
     }
 #endif
 
-    // Do prototype lookup early so that functions and attributes in the prototype can have
-    // precedence over the index and name getters.  
-    JSValue proto = thisObject->prototype();
-    if (proto.isObject() && asObject(proto)->getPropertySlot(exec, propertyName, slot))
-        return true;
-
-    // After this point it is no longer valid to cache any results because of
-    // the impure nature of the property accesses which follow. We can move this 
-    // statement further down when we add ways to mitigate these impurities with, 
-    // for example, watchpoints.
-    slot.disableCaching();
-
-    // Check for child frames by name before built-in properties to
-    // match Mozilla. This does not match IE, but some sites end up
-    // naming frames things that conflict with window properties that
-    // are in Moz but not IE. Since we have some of these, we have to do
-    // it the Moz way.
-    if (auto* scopedChild = thisObject->wrapped().frame()->tree().scopedChild(propertyNameToAtomicString(propertyName))) {
-        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, toJS(exec, scopedChild->document()->domWindow()));
-        return true;
-    }
-
-    // FIXME: Search the whole frame hierarchy somewhere around here.
-    // We need to test the correct priority order.
-
-    // allow window[1] or parent[1] etc. (#56983)
-    Optional<uint32_t> index = parseIndex(propertyName);
-    if (index && index.value() < thisObject->wrapped().frame()->tree().scopedChildCount()) {
-        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum,
-            toJS(exec, thisObject->wrapped().frame()->tree().scopedChild(index.value())->document()->domWindow()));
-        return true;
-    }
-
-    // Allow shortcuts like 'Image1' instead of document.images.Image1
-    Document* document = thisObject->wrapped().frame()->document();
-    if (is<HTMLDocument>(*document)) {
-        AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-        if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
-            slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
-            return true;
-        }
-    }
-
-    return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
+    // (3) Finally, named properties.
+    // Really, this should just be 'return false;' - these should all be on the NPO.
+    return jsDOMWindowGetOwnPropertySlotNamedItemGetter(thisObject, *frame, exec, propertyName, slot);
 }
 
+// Property access sequence is:
+// (1) indexed properties,
+// (2) regular own properties,
+// (3) named properties (in fact, these shouldn't be on the window, should be on the NPO).
 bool JSDOMWindow::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned index, PropertySlot& slot)
 {
-    JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
-    
-    if (!thisObject->wrapped().frame()) {
-        // FIXME: We should have a message here that explains why the property access/function call was
-        // not allowed. 
-        slot.setUndefined();
-        return true;
-    }
+    auto* thisObject = jsCast<JSDOMWindow*>(object);
+    auto* frame = thisObject->wrapped().frame();
 
-    Identifier propertyName = Identifier::from(exec, index);
-    
-    // We need to check for cross-domain access here without printing the generic warning message
-    // because we always allow access to some function, just different ones depending whether access
-    // is allowed.
-    String errorMessage;
-    if (!shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), errorMessage))
-        return jsDOMWindowGetOwnPropertySlotCrossOrigin(thisObject, exec, propertyName, slot, errorMessage);
+    // Indexed getters take precendence over regular properties, so caching would be invalid.
+    slot.disableCaching();
 
-    // Look for overrides before looking at any of our own properties, but ignore overrides completely
-    // if this is cross-domain access.
-    if (JSGlobalObject::getOwnPropertySlotByIndex(thisObject, exec, index, slot))
+    // (1) First, indexed properties.
+    // These are also allowed cross-orgin, so come before the access check.
+    if (frame && index < frame->tree().scopedChildCount()) {
+        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, toJS(exec, frame->tree().scopedChild(index)->document()->domWindow()));
         return true;
-    
-    // Check for child frames by name before built-in properties to
-    // match Mozilla. This does not match IE, but some sites end up
-    // naming frames things that conflict with window properties that
-    // are in Moz but not IE. Since we have some of these, we have to do
-    // it the Moz way.
-    if (auto* scopedChild = thisObject->wrapped().frame()->tree().scopedChild(propertyNameToAtomicString(propertyName))) {
-        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, toJS(exec, scopedChild->document()->domWindow()));
-        return true;
     }
-    
-    // Do prototype lookup early so that functions and attributes in the prototype can have
-    // precedence over the index and name getters.  
-    JSValue proto = thisObject->prototype();
-    if (proto.isObject()) {
-        if (asObject(proto)->getPropertySlot(exec, index, slot))
-            return true;
-    }
 
-    // FIXME: Search the whole frame hierarchy somewhere around here.
-    // We need to test the correct priority order.
+    // Hand off all cross-domain/frameless access to jsDOMWindowGetOwnPropertySlotRestrictedAccess.
+    String errorMessage;
+    if (!frame || !shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), errorMessage))
+        return jsDOMWindowGetOwnPropertySlotRestrictedAccess(thisObject, frame, exec, Identifier::from(exec, index), slot, errorMessage);
 
-    // allow window[1] or parent[1] etc. (#56983)
-    if (index < thisObject->wrapped().frame()->tree().scopedChildCount()) {
-        slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum,
-            toJS(exec, thisObject->wrapped().frame()->tree().scopedChild(index)->document()->domWindow()));
+    // (2) Regular own properties.
+    if (Base::getOwnPropertySlotByIndex(thisObject, exec, index, slot))
         return true;
-    }
 
-    // Allow shortcuts like 'Image1' instead of document.images.Image1
-    Document* document = thisObject->wrapped().frame()->document();
-    if (is<HTMLDocument>(*document)) {
-        // This propertyName is generated by Identifier::from.
-        // This function generates Identifier from String and always returns the non-symbol Identifier.
-        ASSERT(!propertyName.isSymbol());
-        auto atomicPropertyName = static_cast<AtomicStringImpl*>(propertyName.impl());
-        if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
-            slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
-            return true;
-        }
-    }
-
-    return Base::getOwnPropertySlotByIndex(thisObject, exec, index, slot);
+    // (3) Finally, named properties.
+    // Really, this should just be 'return false;' - these should all be on the NPO.
+    return jsDOMWindowGetOwnPropertySlotNamedItemGetter(thisObject, *frame, exec, Identifier::from(exec, index), slot);
 }
 
 void JSDOMWindow::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to