3

I have a constructor defined in a static resource script file. It exposes a single function that returns a Promise. When I instantiate an instance and pass it to a method on a component, Locker Service seems to be wrapping the Promise that is returned, causing it to no longer work.

Something has gone wrong. Action failed: c$LockerTestComp$controller$execute [args.context.getPromise(...).then is not a function] Failing descriptor: {c$LockerTestComp$controller$execute}. Please try again.

If I change the code to call $then$ instead (probably a bad idea), then I get:

Something has gone wrong. Action failed: c$LockerTestComp$controller$execute [# is not a promise] Failing descriptor: {c$LockerTestComp$controller$execute}. Please try again.

If I disable LockerService, then it works.

Do component methods only support primitives? Or is the Locker Service overstepping its bounds?

LockerTestComp.cmp

<aura:component >
    <ltng:require scripts="{!$Resource.LockerTest}" afterScriptsLoaded="{!c.doInit}" />
    <aura:method name="execute" action="c.execute">
        <aura:attribute name="context" type="object" />
    </aura:method>
    Hello World
</aura:component>

LockerTestCompController

({
    doInit : function(component, event, helper) {
        component.execute(new lockerTest());
    },
    execute : function(component, event, helper) {
        var args = event.getParams().arguments;
        args.context.getPromise().then(function() { alert('success') });
    }
})

LockerTest.js (static resource)

window.lockerTest = function() {
    this.getPromise = function(name) {
        return new Promise(function(resolve, reject) { resolve() });
    }
}
2

This appears to be an issue within the LockerService filtering logic where it incorrectly returns a non-Promise object to your controller file. Should be a simple fix. If you file a support ticket you can have them reference our internal work item W-3402504 to track the fix.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.