New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 616981 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Jun 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Android , Windows , Chrome , Mac
Pri: 3
Type: Feature



Sign in to add a comment

registerElement createdCallback "this" value is a TypeError string

Reported by matt...@bitovi.com, Jun 3 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

Example URL:

Steps to reproduce the problem:
Create an html page with this content:

<demo-app></demo-app>
<script>
  document.registerElement("demo-app", {
    prototype: {
      createdCallback: function(){
        console.log(this);
      }
    }
  });
</script>

What is the expected behavior?
Log an element.

What went wrong?
It logs this string instead:

TypeError: Cannot read property 'toLowerCase' of undefined
    at Object.InjectedScript._describe (<anonymous>:175:71)
    at InjectedScript.RemoteObject (<anonymous>:194:58)
    at Object.InjectedScript._wrapObject (<anonymous>:60:13)
    at Object.InjectedScript.wrapObject (<anonymous>:49:13)
    at demo-app.document.registerElement.createdCallback (two.html:6)
    at two.html:3

Does it occur on multiple sites: N/A

Is it a problem with a plugin? N/A 

Did this work before? N/A 

Does this work in other browsers? N/A 

Chrome version: 50.0.2661.102  Channel: n/a
OS Version: OS X 10.11.3
Flash Version: Shockwave Flash 21.0 r0
 

Comment 1 by matt...@bitovi.com, Jun 3 2016

Ah, the problem is that my prototype is not an existing element... this error could be better.
Cc: rnimmagadda@chromium.org
Labels: Needs-Feedback
@matthew: Could you please let us know, if we can go ahead and close this issue based on your comment #1.

Thank you.

Comment 3 by matt...@bitovi.com, Jun 3 2016

@rnimmagadda: I'm pretty sure this is a bug. I don't know what the spec says, but I doubt the value of `this` should be a string.
Project Member

Comment 4 by sheriffbot@chromium.org, Jun 3 2016

Labels: -Needs-Feedback Needs-Review
Owner: rnimmagadda@chromium.org
Thank you for providing more feedback. Adding requester "rnimmagadda@chromium.org" for another review and adding "Needs-Review" label for tracking.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Labels: -Needs-Review Needs-Feedback
Please check to see if there is similar behavior on Safari and Firefox.

If not, please attach an HTML file that demonstrates the problem.

Owner: ----
@matthew: Could you please respond to comment #5
 
Thank you.

Comment 7 by matt...@bitovi.com, Jun 6 2016

Safari doesn't support registerElement so I can't test there.  Tested in Firefox, it doesn't happen there, logs the element.

Comment 8 by matt...@bitovi.com, Jun 6 2016

Attaching an html file demonstrating the bug.
wc-bug.html
181 bytes View Download
Project Member

Comment 9 by sheriffbot@chromium.org, Jun 6 2016

Labels: -Needs-Feedback Needs-Review
Owner: shrike@chromium.org
Thank you for providing more feedback. Adding requester "shrike@chromium.org" for another review and adding "Needs-Review" label for tracking.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Components: Blink>HTML
Owner: ----
Cc: dominicc@chromium.org
Components: -Blink>HTML Blink>WebComponents Platform>DevTools>HTML
Labels: -Pri-2 -Type-Compat OS-Android OS-Chrome OS-Linux OS-Windows Pri-3 Type-Feature
Status: Untriaged (was: Unconfirmed)
Comment 1 is probably right; console.log is trying to format 'this', but you've set an odd prototype (the {createdCallback: ...} object.)

We could make the inspector try to work out there's a custom element underneath here and dig it out. I guess that is what Firefox is doing.
I don't think this is a bug with the inspector. The value of 'this' is not the element. If you change the example and get rid of the console.log:

<demo-app></demo-app>
<script>
  document.registerElement("demo-app", {
    prototype: {
      createdCallback: function(){
        this.appendChild(document.createElement("div"));
      }
    }
  });
</script>

It throws "Uncaught TypeError: this.appendChild is not a function".  Because 'this' is a string.

Comment 13 by l...@chromium.org, Jun 7 2016

Owner: l...@chromium.org
Status: Started (was: Untriaged)
It looks like both Firefox and Chrome are getting the actual element as 'this', but in Chrome's case, the inspector can't format it correctly.  Matthew's code in #12 also prints an error in Firefox.

Inspector knows that 'this''s subtype == 'node', but incorrectly formats it like an error string because of the error thrown when it has no nodeName after the custom prototype is set.

For now, we can emulate Firefox's behavior by modifying our inspector's formatter to use the constructor.name when the nodeName is not present.
Re: comment 12, this.appendChild is basically the same problem. appendChild comes from the Element prototype. But something like Element.prototype.appendChild.call(this, document.createElement('div')) should work.

Comment 17 by l...@chromium.org, Jun 15 2016

Status: Fixed (was: Started)

Sign in to add a comment