Skip to content

Commit

Permalink
fix(engine): never access props from proxies (#546)
Browse files Browse the repository at this point in the history
* fix(engine): never access props from proxies

* fix(engine): never access props from proxies

* fix(engine): never access props from proxies
  • Loading branch information
caridy authored and pmdartus committed Aug 1, 2018
1 parent b77df3a commit d0cf318
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
26 changes: 3 additions & 23 deletions packages/lwc-engine/src/faux-shadow/shadow-root.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import assert from "../shared/assert";
import { isNull, create, assign, isUndefined, toString, getOwnPropertyDescriptor, ArrayReduce, } from "../shared/language";
import { create, assign, isUndefined, getOwnPropertyDescriptor, ArrayReduce } from "../shared/language";
import { addShadowRootEventListener, removeShadowRootEventListener } from "./events";
import { shadowRootQuerySelector, shadowRootQuerySelectorAll, shadowRootChildNodes, getPatchedCustomElement, isNodeOwnedBy } from "./traverse";
import { shadowRootQuerySelector, shadowRootQuerySelectorAll, shadowRootChildNodes, isNodeOwnedBy } from "./traverse";
import { getInternalField, setInternalField, createFieldName } from "../shared/fields";
import { getInnerHTML } from "../3rdparty/polymer/inner-html";
import { getTextContent } from "../3rdparty/polymer/text-content";
import { compareDocumentPosition, DOCUMENT_POSITION_CONTAINED_BY, getNodeKey } from "./node";
import { compareDocumentPosition, DOCUMENT_POSITION_CONTAINED_BY } from "./node";
// it is ok to import from the polyfill since they always go hand-to-hand anyways.
import { ElementPrototypeAriaPropertyNames } from "../polyfills/aria-properties/polyfill";
import { unwrap } from "./traverse-membrane";
Expand Down Expand Up @@ -155,16 +155,6 @@ const ArtificialShadowRootDescriptors: PropertyDescriptorMap = {
querySelector: {
value(this: ShadowRoot, selector: string): Element | null {
const node = shadowRootQuerySelector(this, selector);
if (process.env.NODE_ENV !== 'production') {
const host = getHost(this);
const isRoot = isUndefined(getNodeKey(host));
if (isNull(node) && !isRoot) {
// note: we don't show errors for root elements since their light dom is always empty in fallback mode
if (getPatchedCustomElement(host).querySelector(selector)) {
assert.logWarning(`this.template.querySelector() can only return elements from the template declaration of ${toString(host)}. It seems that you are looking for elements that were passed via slots, in which case you should use this.querySelector() instead.`);
}
}
}
return node as Element;
},
enumerable: true,
Expand All @@ -173,16 +163,6 @@ const ArtificialShadowRootDescriptors: PropertyDescriptorMap = {
querySelectorAll: {
value(this: ShadowRoot, selector: string): Element[] {
const nodeList = shadowRootQuerySelectorAll(this, selector);
if (process.env.NODE_ENV !== 'production') {
const host = getHost(this);
const isRoot = isUndefined(getNodeKey(host));
if (nodeList.length === 0 && !isRoot) {
// note: we don't show errors for root elements since their light dom is always empty in fallback mode
if (getPatchedCustomElement(host).querySelector(selector)) {
assert.logWarning(`this.template.querySelectorAll() can only return elements from template declaration of ${toString(host)}. It seems that you are looking for elements that were passed via slots, in which case you should use this.querySelectorAll() instead.`);
}
}
}
return nodeList;
},
enumerable: true,
Expand Down
4 changes: 0 additions & 4 deletions packages/lwc-engine/src/faux-shadow/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ import { getTextContent } from "../3rdparty/polymer/text-content";
import { getInnerHTML } from "../3rdparty/polymer/inner-html";
import { getHost, getShadowRoot } from "./shadow-root";

export function getPatchedCustomElement(element: HTMLElement): HTMLElement {
return traverseMembraneWrap(element);
}

const iFrameContentWindowGetter: (this: HTMLIFrameElement) => Window = getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow')!.get!;

function getNodeOwner(node: Node): HTMLElement | null {
Expand Down

0 comments on commit d0cf318

Please sign in to comment.