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'; 269801e3c558f3df82f01ac626b6171032afa33819machenbach@chromium.orgdescription('Test Promise.resolve as cast'); 27bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 28bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar result = undefined; 29bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar result2 = undefined; 30bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 31bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar resolve; 32bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgvar value = new Promise(function (r) { resolve = r;} ); 339801e3c558f3df82f01ac626b6171032afa33819machenbach@chromium.orgvar promise = Promise.resolve(value); 34bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 359801e3c558f3df82f01ac626b6171032afa33819machenbach@chromium.org// If [[IsPromise]] is true, Promise.resolve simply returns argument. 36bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgshouldBe('promise', 'value'); 37bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 38bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgpromise.then(function(res) { 39bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org result = res; 40bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org shouldBeEqualToString('result', 'hello'); 41bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 429801e3c558f3df82f01ac626b6171032afa33819machenbach@chromium.org return Promise.resolve(42).then(function (res) { 43bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org result2 = res; 44bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org shouldBe('result2', '42'); 45bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org }); 46bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}).then(function () { 47bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org testPassed('fulfilled'); 48bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org finishJSTest(); 49bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}, function() { 50bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org testFailed('rejected'); 51bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org finishJSTest(); 52bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org}); 53bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.org 54bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgresolve('hello'); 55bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgshouldBe('result', 'undefined'); 56bcc36723a2ace28fa3b0d7dd0d1de926d313fff9machenbach@chromium.orgshouldBe('result2', 'undefined'); 57