// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1.  Redistributions of source code must retain the above copyright
//     notice, this list of conditions and the following disclaimer.
// 2.  Redistributions in binary form must reproduce the above copyright
//     notice, this list of conditions and the following disclaimer in the
//     documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Flags: --harmony
'use strict';
description('Test Promise.prototype.then');

var resolve;
var result;
var thisInOnFulfilled;
var thisInInit;

var firstPromise = new Promise(function(newResolve) {
  thisInInit = this;
  resolve = newResolve;
});

var secondPromise = firstPromise.then(function(localResult) {
  thisInOnFulfilled = this;
  shouldBe('thisInOnFulfilled', 'undefined');
  result = localResult;
  shouldBeEqualToString('result', 'hello');
  return 'world';
});

shouldBe('thisInInit', 'undefined');
shouldBeTrue('firstPromise instanceof Promise');
shouldBeTrue('secondPromise instanceof Promise');

secondPromise.then(undefined, 37).then(function(localResult) {
  result = localResult;
  shouldBeEqualToString('result', 'world');
  throw 'exception'
}).then(1, 2).then(function() {
  testFailed('resolved');
}, function(localResult) {
  testPassed('rejected');
  result = localResult;
  shouldBeEqualToString('result', 'exception');
}).then(function() {
  testPassed('resolved');
  finishJSTest();
}, function() {
  testFailed('rejected');
  finishJSTest();
});

resolve('hello');
