1bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// Copyright 2014 the V8 project authors. All rights reserved. 2bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// 4bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// Redistribution and use in source and binary forms, with or without 5bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// modification, are permitted provided that the following conditions 6bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// are met: 7bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// 1. Redistributions of source code must retain the above copyright 8bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// notice, this list of conditions and the following disclaimer. 9bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// 2. Redistributions in binary form must reproduce the above copyright 10bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// notice, this list of conditions and the following disclaimer in the 11bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// documentation and/or other materials provided with the distribution. 12bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// 13bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 24bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org// Flags: --harmony 25bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org'use strict'; 26bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgdescription('An exception thrown from an onFulfilled callback should reject the Promise.'); 27bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 28bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar thisInThenCallback; 29bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar result; 30bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 31bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgnew Promise(function(resolve) { 32bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org resolve('hello'); 33bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}).then(function(result) { 34bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org throw 'foobar'; 35bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}).then(function(localResult) { 36bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org testFailed('Unexpected invocation of onFulfilled'); 37bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}, function(localResult) { 38bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org thisInThenCallback = this; 39bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org shouldBe('thisInThenCallback', 'undefined'); 40bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org result = localResult; 41bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org shouldBeEqualToString('result', 'foobar'); 42bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org finishJSTest(); 43bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}); 44