Open luisespinal opened 7 years ago
I would expect the behavior you experience. It's common to need to explicitly bind a method to object when passing the method as a function. Rather than patching this code, I would expect a bound function to passed into the promise:
parser.parseFromString.bind(parser)
DOMParser fails to bind to the proper "this" object when a DOMParser object is created outside of a promise, but used within a "thenable" block.
For instance.
Will cause the following error to occur.
And that is because the "this" object has changed from where the parser was created and from the moment the promise is being evaluated. The error is on the third line below (in dom-parser.js)
The options variable is going to be undefined (because the "this" object referring to the context being executed in the current "thenable" block does not have such a property. Then when we try to create domBuilder, it inevitably breaks.
To this:
I've tested all changes, and my preference would be the last one.
Until (and if) such a change is incorporated, the workaround I'm using is number one and two above, depending on context.