salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.61k stars 395 forks source link

unwrap() in membrane.ts needs a guard against falsy values #352

Closed ravijayaramappa closed 6 years ago

ravijayaramappa commented 6 years ago

Description

https://github.com/salesforce/lwc/blob/master/packages/lwc-engine/src/framework/membrane.ts#L27 unwrap() method fails with a javascript exception if passed an undefined value

Steps to Reproduce

Setup an aura component to include a lwc child child component should have a public method which returns no value Call the child's public method from the aura parent notice the javascript exception

http://playground.sfdc.es/projects/edit

InteropComponent.prototype.setupMethods = function () {
    var self = this;
    this.getPublicMethodNames().forEach(function (m) {
        self[m] = function () {
            if (!self.rendered) {
                return $A.warning('Methods are not available until the component is rendered');
            }
            var elmt = this.getElement();
            var rv = elmt[m].apply(elmt, arguments);
            return $A.componentService.moduleEngine['unwrap'](rv); **// rv can be undefined**
        };
    });
};

Expected Results

return undefined and not fail with a javascript error

Actual Results

Browsers Affected

all

Version

Possible Solution

guard unwrap() against falsy arguments

Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

davidturissini commented 6 years ago

I don't think we need this function anymore. We can just export observable membrane's unwrap. If user needs to get original iframe content window, HTMLIFrameElement.prototype.contentWindow is available.