Uncaught Exception: Attempted to assign to readonly property (at ContentView.js:...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Sep 2017 04:20:05 +0000 (04:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Sep 2017 04:20:05 +0000 (04:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177587

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-09-27
Reviewed by Matt Baker.

We allow a representedObject to be a string. In strict mode attempting to set
a property on a string results in a TypeError. So we should be careful not to
do this in the rare cases where our representedObject is the a string.

* UserInterface/Views/ContentView.js:
(WI.ContentView.contentViewForRepresentedObject):
(WI.ContentView.closedContentViewForRepresentedObject):
Avoid setting a property on strings. ContentViews backed by a String aren't typically
shared anyways, so the property case would not be useful. If a client really wants
to share they could use `new String(...)` as the representedObject.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@222599 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/ContentView.js

index 21250bb..0cd64ea 100644 (file)
@@ -1,3 +1,21 @@
+2017-09-27  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Uncaught Exception: Attempted to assign to readonly property (at ContentView.js:​206:​34)​
+        https://bugs.webkit.org/show_bug.cgi?id=177587
+
+        Reviewed by Matt Baker.
+
+        We allow a representedObject to be a string. In strict mode attempting to set
+        a property on a string results in a TypeError. So we should be careful not to
+        do this in the rare cases where our representedObject is the a string.
+
+        * UserInterface/Views/ContentView.js:
+        (WI.ContentView.contentViewForRepresentedObject):
+        (WI.ContentView.closedContentViewForRepresentedObject):
+        Avoid setting a property on strings. ContentViews backed by a String aren't typically
+        shared anyways, so the property case would not be useful. If a client really wants
+        to share they could use `new String(...)` as the representedObject.
+
 2017-09-27  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: Missing checks in DebuggerSidebarPanel for DOM debugging support
index 21e768a..012c6a0 100644 (file)
@@ -199,14 +199,16 @@ WI.ContentView = class ContentView extends WI.View
             return null;
 
         console.assert(newContentView.representedObject === resolvedRepresentedObject, "createFromRepresentedObject and resolvedRepresentedObjectForRepresentedObject are out of sync for type", representedObject.constructor.name);
-        newContentView.representedObject[WI.ContentView.ContentViewForRepresentedObjectSymbol] = newContentView;
+        if (typeof resolvedRepresentedObject === "object")
+            newContentView.representedObject[WI.ContentView.ContentViewForRepresentedObjectSymbol] = newContentView;
         return newContentView;
     }
 
     static closedContentViewForRepresentedObject(representedObject)
     {
         let resolvedRepresentedObject = WI.ContentView.resolvedRepresentedObjectForRepresentedObject(representedObject);
-        resolvedRepresentedObject[WI.ContentView.ContentViewForRepresentedObjectSymbol] = null;
+        if (typeof resolvedRepresentedObject === "object")
+            resolvedRepresentedObject[WI.ContentView.ContentViewForRepresentedObjectSymbol] = null;
     }
 
     static resolvedRepresentedObjectForRepresentedObject(representedObject)