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

Issue 643049 link

Starred by 5 users

Issue metadata

Status: Fixed
Owner:
Closed: Oct 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug

Blocking:
issue 648915



Sign in to add a comment

Chrome does not invoke the Symbol.iterator when converting the sequence of observedAttributes

Project Member Reported by davaajav@google.com, Sep 1 2016

Issue description

LayoutTests/fast/custom-elements/CustomElementRegistry.html:231
LayoutTests/fast/custom-elements/attribute-changed-callback.html:171

 
Blockedon: 643030
Project Member

Comment 2 by sheriffbot@chromium.org, Sep 1 2016

Labels: Hotlist-Google
Blocking: 643030
Blockedon: -643030
Cc: kojii@chromium.org bashi@chromium.org
Components: Blink>Bindings Blink>DOM
Labels: -Pri-3 Pri-2
Status: Available (was: Untriaged)
We just use toImplArray to convert the property to a sequence.

Here's the spec for define:
https://html.spec.whatwg.org/#dom-customelementregistry-define

Step 10.6.2 says:

"If observedAttributesIterable is not undefined, then set observedAttributes to the result of converting observedAttributesIterable to a sequence<DOMString>. Rethrow any exceptions from the conversion."

Here's the definition of how to do that conversion:

https://heycam.github.io/webidl/#es-sequence

We should probably be using toV8Sequence:
https://cs.chromium.org/chromium/src/third_party/WebKit/Source/bindings/core/v8/V8Binding.h?sq=package:chromium&rcl=1473247219&l=733

However it looks like it doesn't exactly match the spec? There's nothing in the spec about dates; the implementation doesn't retrieve symbol.iterator; etc.

Comment 6 by bashi@chromium.org, Sep 7 2016

Yeah, toV8Sequence is a bit out-of-date. "Date" was removed from the spec.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=22824

In general we should make it up-to-date but we should also be careful not to break existing behavior. I'll take a closer look later.
Patch up at https://codereview.chromium.org/2316263003 by bashi-san
Status: Fixed (was: Available)
Project Member

Comment 11 by bugdroid1@chromium.org, Sep 15 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/75613110cd274c6fee47675dfe78df3ba20205f4

commit 75613110cd274c6fee47675dfe78df3ba20205f4
Author: davaajav <davaajav@google.com>
Date: Thu Sep 15 02:26:57 2016

Custom Elements: layout tests for observedAttributes

1. attributeChangedCallback should be fired only from
the elements in observedAttributes
2. Checks for cases when converting observedAttributes
to sequence<DOMString> should throw TypeError
https://heycam.github.io/webidl/#create-sequence-from-iterable

BUG= 643049 

Review-Url: https://codereview.chromium.org/2321903003
Cr-Commit-Position: refs/heads/master@{#418761}

[modify] https://crrev.com/75613110cd274c6fee47675dfe78df3ba20205f4/third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html

Blocking: -643030 648915
Owner: bashi@chromium.org
Status: Assigned (was: Fixed)
It looks like sequence conversion should rethrow exceptions. In this algorithm:

https://heycam.github.io/webidl/#create-sequence-from-iterable

Step 2 works, Davaa's test shows this.
Step 4.2, 4.5 seems to swallow exceptions? We didn't add a test for this and rniwa says a WebKit custom elements test indicates we don't transmit that exception correctly.

Comment 13 by bashi@chromium.org, Sep 23 2016

Owner: dominicc@chromium.org
Hmm, we don't use v8::TryCatch in toImplSequence so I think if there is an exception it should be thrown. Do you have a repro case?
See also:  issue 393866  - it'd be nice to get toImplSequence used for handling sequence<> correctly elsewhere too.
Cc: dominicc@chromium.org
Owner: bashi@chromium.org
Status: Fixed (was: Assigned)
I looked for the repro case but couldn't find it. I will reopen if I find it.
Status: Assigned (was: Fixed)
OK, I have created a repro for you:

http://codepen.io/anon/pen/WGmObZ

This should throw 'bar' from define but it does not. The problem is precisely because you're not using TryCatch. toImplSequence/getEsIterator should be using TryCatch to transmit the exception to the ExceptionState parameter that those methods take. It doesn't.

Or should the caller use ExceptionState *and* TryCatch? (Why can ExceptionState transmit V8 exceptions then?)

'use strict';

let attrs = {};
attrs[Symbol.iterator] = function*() {
  throw 'bar';
}

class X extends HTMLElement {
  static get observedAttributes() {
    console.log('retrieving attrs');
    return attrs;
  }
  attributeChangedCallback(name) {
    console.log(`${name} changed`)
  }
}

customElements.define('x-x', X);

Comment 17 by bashi@chromium.org, Oct 25 2016

Cc: haraken@chromium.org jochen@chromium.org
Thanks for the repro. I confirmed "bar" isn't thrown.

I'm still wondering why an exception wasn't thrown. IIUC when we don't use v8::TryCatch, an exception is already thrown if ToLocal() fails.

https://cs.chromium.org/chromium/src/third_party/WebKit/Source/bindings/core/v8/V8Binding.h?rcl=0&l=1045

jochen@, haraken@: Am I missing something? Should we use v8::TryCatch in toImplSequence() to transmit an exception to ExceptionState?
An exception should have been thrown when ToLocal() fails.

Is it possible that we have a v8::TryCatch somewhere above the stack and it is suppressing the exception?


The problem is getEsIterator doesn't use TryCatch to populate the ExceptionState with the exception.

An API where you have to use TryCatch *and* ExceptionState doesn't make much sense to me--we may as well just use TryCatch.

An API where you have to use ExceptionState but *can't* have TryCatch somewhere up the stack doesn't make much sense to me either.

Some APIs are called with JS callers on the stack, others without, that is part of the reason ExceptionState exists.

Hence you should catch the exceptions emanating from @@iterator and propagate them to the ExceptionState your API uses.

Comment 20 by bashi@chromium.org, Oct 26 2016

Thanks for the clarification. I understand your point and it makes sense to me. I'll create CL to use TryCatch.

Comment 22 by bashi@chromium.org, Oct 26 2016

Status: Fixed (was: Assigned)

Sign in to add a comment