Combine duplicate code about ref/ptr comparison

Review URL: https://codereview.chromium.org/379023002

git-svn-id: svn://svn.chromium.org/blink/trunk@177727 bbb929c8-8fbe-4397-9dbb-9b2b20218538