stack overflow when returning an ES6 proxy through a promise

蓝咒 提交于 2019-12-06 15:55:55

Your problem is that your proxy always returns a function for accesses on any property, including then. That will make promises implementations treat it as a thenable, trying to to resolve it - where your code went horribly wrong. But you should fix the root of the issue:

get (target, propertyKey, receiver) {
    if (!(propertyKey in target))
        return undefined;
    else if (typeof target[propertyKey] != "function")
        return …;
    else
        return function resourceFunctionProxy() {
            …

It's a shot in the blue, but you might be looking for

return function proxyPromiseWrapper(thenCallback) {
    return options.originalObject.then(function(result) {
        const resultOptions = Object.assign({}, options, {target: result});
        const innerProxy = self.create(resultOptions);
        return thenCallback(innerProxy);
    });
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!