mirror of
				https://github.com/tc39/test262.git
				synced 2025-11-04 05:33:50 +01:00 
			
		
		
		
	sourceRevisionAtLastExport: 33f2fb0e53d135f0ee17cfccd9d993eb2a6f47de targetRevisionAtLastExport: 31340cbd9add103f586d501b0c3354b7b182abc0
		
			
				
	
	
		
			120 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
// Copyright 2018 the V8 project authors. All rights reserved.
 | 
						|
// Use of this source code is governed by a BSD-style license that can be
 | 
						|
// found in the LICENSE file.
 | 
						|
 | 
						|
// Flags: --allow-natives-syntax
 | 
						|
 | 
						|
function assertFulfilledWith(expected, thenable) {
 | 
						|
  assertPromiseResult(thenable, v => assertEquals(expected, v));
 | 
						|
}
 | 
						|
 | 
						|
(function() {
 | 
						|
  function foo() { return Promise.resolve(); }
 | 
						|
  assertFulfilledWith(undefined, foo());
 | 
						|
  assertFulfilledWith(undefined, foo());
 | 
						|
  %OptimizeFunctionOnNextCall(foo);
 | 
						|
  assertFulfilledWith(undefined, foo());
 | 
						|
})();
 | 
						|
 | 
						|
(function() {
 | 
						|
  function foo(x) { return Promise.resolve(x); }
 | 
						|
  assertFulfilledWith(3, foo(3));
 | 
						|
  assertFulfilledWith(3, foo(3));
 | 
						|
  %OptimizeFunctionOnNextCall(foo);
 | 
						|
  assertFulfilledWith(3, foo(3));
 | 
						|
})();
 | 
						|
 | 
						|
(function() {
 | 
						|
  function foo(x, y) { return Promise.resolve(x, y); }
 | 
						|
  assertFulfilledWith(1, foo(1, 0));
 | 
						|
  assertFulfilledWith(2, foo(2, 1));
 | 
						|
  %OptimizeFunctionOnNextCall(foo);
 | 
						|
  assertFulfilledWith(3, foo(3, 2));
 | 
						|
})();
 | 
						|
 | 
						|
(function() {
 | 
						|
  function foo(x) { return Promise.resolve({x}); }
 | 
						|
  assertFulfilledWith({x:1}, foo(1));
 | 
						|
  assertFulfilledWith({x:2}, foo(2));
 | 
						|
  %OptimizeFunctionOnNextCall(foo);
 | 
						|
  assertFulfilledWith({x:3}, foo(3));
 | 
						|
})();
 | 
						|
 | 
						|
(function() {
 | 
						|
  function foo(x) { return Promise.resolve(Promise.resolve(x)); }
 | 
						|
  assertFulfilledWith(null, foo(null));
 | 
						|
  assertFulfilledWith('a', foo('a'));
 | 
						|
  %OptimizeFunctionOnNextCall(foo);
 | 
						|
  assertFulfilledWith(42, foo(42));
 | 
						|
})();
 | 
						|
 | 
						|
(function() {
 | 
						|
  const thenable = new class Thenable {
 | 
						|
    then(fulfill, reject) {
 | 
						|
      fulfill(1);
 | 
						|
    }
 | 
						|
  };
 | 
						|
  function foo() { return Promise.resolve(thenable); }
 | 
						|
  assertFulfilledWith(1, foo());
 | 
						|
  assertFulfilledWith(1, foo());
 | 
						|
  %OptimizeFunctionOnNextCall(foo);
 | 
						|
  assertFulfilledWith(1, foo());
 | 
						|
})();
 | 
						|
 | 
						|
(function() {
 | 
						|
  const MyPromise = class MyPromise extends Promise {};
 | 
						|
 | 
						|
  (function() {
 | 
						|
    function foo() { return MyPromise.resolve(); }
 | 
						|
    assertFulfilledWith(undefined, foo());
 | 
						|
    assertFulfilledWith(undefined, foo());
 | 
						|
    %OptimizeFunctionOnNextCall(foo);
 | 
						|
    assertFulfilledWith(undefined, foo());
 | 
						|
  })();
 | 
						|
 | 
						|
  (function() {
 | 
						|
    function foo(x) { return MyPromise.resolve(x); }
 | 
						|
    assertFulfilledWith(3, foo(3));
 | 
						|
    assertFulfilledWith(3, foo(3));
 | 
						|
    %OptimizeFunctionOnNextCall(foo);
 | 
						|
    assertFulfilledWith(3, foo(3));
 | 
						|
  })();
 | 
						|
 | 
						|
  (function() {
 | 
						|
    function foo(x, y) { return MyPromise.resolve(x, y); }
 | 
						|
    assertFulfilledWith(1, foo(1, 0));
 | 
						|
    assertFulfilledWith(2, foo(2, 1));
 | 
						|
    %OptimizeFunctionOnNextCall(foo);
 | 
						|
    assertFulfilledWith(3, foo(3, 2));
 | 
						|
  })();
 | 
						|
 | 
						|
  (function() {
 | 
						|
    function foo(x) { return MyPromise.resolve({x}); }
 | 
						|
    assertFulfilledWith({x:1}, foo(1));
 | 
						|
    assertFulfilledWith({x:2}, foo(2));
 | 
						|
    %OptimizeFunctionOnNextCall(foo);
 | 
						|
    assertFulfilledWith({x:3}, foo(3));
 | 
						|
  })();
 | 
						|
 | 
						|
  (function() {
 | 
						|
    function foo(x) { return MyPromise.resolve(Promise.resolve(x)); }
 | 
						|
    assertFulfilledWith(null, foo(null));
 | 
						|
    assertFulfilledWith('a', foo('a'));
 | 
						|
    %OptimizeFunctionOnNextCall(foo);
 | 
						|
    assertFulfilledWith(42, foo(42));
 | 
						|
  })();
 | 
						|
 | 
						|
  (function() {
 | 
						|
    const thenable = new class Thenable {
 | 
						|
      then(fulfill, reject) {
 | 
						|
        fulfill(1);
 | 
						|
      }
 | 
						|
    };
 | 
						|
    function foo() { return MyPromise.resolve(thenable); }
 | 
						|
    assertFulfilledWith(1, foo());
 | 
						|
    assertFulfilledWith(1, foo());
 | 
						|
    %OptimizeFunctionOnNextCall(foo);
 | 
						|
    assertFulfilledWith(1, foo());
 | 
						|
  })();
 | 
						|
})();
 |