Re: [w3c/webcomponents] document.currentScript from a script in a shadow tree. (#477)

I'm sorry if I miss something. From reading this discussion I cannot see why `document.currentScript`  violates the encapsulation in the way Custom Elements don't. As exposing shadow tree is trivial and could be done via various means, even without touching `currentScript`.

Consider the element:
```js
customElements.define('expose-shadow-root',class extends HTMLElement{
    connectedCallback(){
        window.exposeShadowRoot = this.getRootNode();
    }
})
```
Then in putting `<expose-shadow-root>` into a shadow root is really violating it, but putting following script into shadow root is not.
```html
<script>
    document.currentScript.getRootNode().getElementById('horn').addEventListener('click',()=>{alert('beep')});
</script>
```


However, non-violating use of `currentScript` is blocked while violating encapsulation via CE is not.

In my opinion as long as there is no JS encapsulation for custom elements, exposing shadow root programmatically will always be trivial.
But without `currentScript` accessing the currentRoot is blocked.

Yes, I know I can define and create an instance of a custom element instead of this script, but that's like using sledgehammer to crack a peanut.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/477#issuecomment-351697502

Received on Thursday, 14 December 2017 12:28:55 UTC