Skip to content

TypeError: Right-hand side of 'instanceof' is not an object#38350

Closed
rifler wants to merge 1 commit intoangular:masterfrom
rifler:patch-1
Closed

TypeError: Right-hand side of 'instanceof' is not an object#38350
rifler wants to merge 1 commit intoangular:masterfrom
rifler:patch-1

Conversation

@rifler
Copy link
Contributor

@rifler rifler commented Aug 5, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove bot requested a review from mhevery August 5, 2020 19:44
@AndrewKushnir AndrewKushnir added the area: zones Issues related to zone.js label Aug 5, 2020
@ngbot ngbot bot added this to the needsTriage milestone Aug 5, 2020
@AndrewKushnir
Copy link
Contributor

Hi @rifler, thanks for creating this PR.

It looks like it's missing some critical information to make this PR actionable, specifically:

  • problem description, which problem this PR resolves
  • links to open issues (if any)
  • tests that would verify this change (ideally, the set of tests that would fail without the change)

I will close this PR for now, feel free to reopen or create a new one once you have the necessary information and tests.

Thank you.

@rifler
Copy link
Contributor Author

rifler commented Aug 6, 2020

@AndrewKushnir instanceof is not safe operation, so if you monkeypatch such substantial method as Object.prototype.toString, you have to use try..catch

@rifler
Copy link
Contributor Author

rifler commented Aug 6, 2020

@AndrewKushnir I create an issue - #38361

but cannot reopen pull-request

@AndrewKushnir
Copy link
Contributor

@rifler I've re-opened this PR based on #38361 (comment). Thank you.

Comment on lines 52 to 55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using try/catch, I think maybe

if (typeof Promise !== 'undefined' && this instanceof Promise) {
  return PROMISE_OBJECT_TO_STRING;
}

will be better, although the code still fails if some app set Promise to some invalid value such as window.Promise = 1, but in that case, the app already fails in a lot of other places.

@JiaLiPassion
Copy link
Contributor

@rifler, thanks and year typeof Promise === 'function' is better.
Could you also add a test case to test it?

@mhevery
Copy link
Contributor

mhevery commented Aug 18, 2020

LGTM after @JiaLiPassion comments are resolved.

@rifler
Copy link
Contributor Author

rifler commented Aug 20, 2020

@JiaLiPassion can you please give me advice how to write unit test for Zone.__load_patch?

Maybe type checking is enough here?

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@JiaLiPassion
Copy link
Contributor

@rifler , I just added one test case.
And please do the follow cleanups.

git rebase master -i

  1. then squash the current 4 commits to 1 commit.
  2. And then modify the commit message to following the commit guide line here https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit
    something like
fix(zone.js): zone.js toString patch should check typeof Promise is function

Close #38361

zone.js monkey patch toString, and check the instance is `Promise` or not by using `instanceof Promise`,
sometimes when Promise is not available, the `instanceof` operation fails and throw `TypeError: Right-hand side of 'instanceof' is not an object`, this PR check `typeof Promise` equals to function or not to prevent the error.

@JiaLiPassion JiaLiPassion added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Aug 21, 2020
…unction

Close angular#38361

zone.js monkey patch toString, and check the instance is `Promise` or not by using `instanceof Promise`,
sometimes when Promise is not available, the `instanceof` operation fails
and throw `TypeError: Right-hand side of 'instanceof' is not an object`
this PR check `typeof Promise` equals to function or not to prevent the error.
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@rifler
Copy link
Contributor Author

rifler commented Aug 24, 2020

fixed

@JiaLiPassion
Copy link
Contributor

LGTM.

@JiaLiPassion JiaLiPassion self-requested a review August 25, 2020 00:38
@JiaLiPassion JiaLiPassion removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Aug 25, 2020
@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Aug 25, 2020
@AndrewKushnir
Copy link
Contributor

Presubmit

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Aug 25, 2020
mhevery pushed a commit that referenced this pull request Aug 25, 2020
…unction (#38350)

Close #38361

zone.js monkey patch toString, and check the instance is `Promise` or not by using `instanceof Promise`,
sometimes when Promise is not available, the `instanceof` operation fails
and throw `TypeError: Right-hand side of 'instanceof' is not an object`
this PR check `typeof Promise` equals to function or not to prevent the error.

PR Close #38350
@mhevery mhevery closed this in 18e474f Aug 25, 2020
subratpalhar92 pushed a commit to SUBRATPALHAR-ALL-JAVASCRIPT/angular that referenced this pull request Aug 29, 2020
…unction (angular#38350)

Close angular#38361

zone.js monkey patch toString, and check the instance is `Promise` or not by using `instanceof Promise`,
sometimes when Promise is not available, the `instanceof` operation fails
and throw `TypeError: Right-hand side of 'instanceof' is not an object`
this PR check `typeof Promise` equals to function or not to prevent the error.

PR Close angular#38350
subratpalhar92 added a commit to SUBRATPALHAR-ALL-JAVASCRIPT/angular that referenced this pull request Aug 31, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…unction (angular#38350)

Close angular#38361

zone.js monkey patch toString, and check the instance is `Promise` or not by using `instanceof Promise`,
sometimes when Promise is not available, the `instanceof` operation fails
and throw `TypeError: Right-hand side of 'instanceof' is not an object`
this PR check `typeof Promise` equals to function or not to prevent the error.

PR Close angular#38350
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: zones Issues related to zone.js cla: yes target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants