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('Test whether Promise treats thenable correctly.'); 27bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 28bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar thisValue; 29bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar result; 30bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar value = { 31bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org then: function(onFulfilled) { 32bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org testPassed('value.then is called.'); 33bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org thisValue = this; 34bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org shouldBe('thisValue', 'value'); 35bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org onFulfilled('hello'); 36bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org } 37bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}; 38bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 39bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgnew Promise(function(resolve) { 40bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org resolve(value); 41bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}).then(function(localResult) { 42bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org testPassed('fulfilled'); 43bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org result = localResult; 44bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org shouldBeEqualToString('result', 'hello'); 45bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org finishJSTest(); 46bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}, function() { 47bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org testFailed('rejected'); 48bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org finishJSTest(); 49bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}); 50bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 51bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgdebug('The promise is not fulfilled now.'); 52