Fix issue 8665

Integrate two upstream fixes from V8:

1)
Review URL: https://codereview.chromium.org/741683002

2)
Review URL: https://codereview.chromium.org/736583007
Issue URL: https://code.google.com/p/v8/issues/detail?id=3708

Fixes #8665.