mirror of
				https://github.com/tc39/test262.git
				synced 2025-11-04 13:44:29 +01:00 
			
		
		
		
	sourceRevisionAtLastExport: 33f2fb0e53d135f0ee17cfccd9d993eb2a6f47de targetRevisionAtLastExport: 31340cbd9add103f586d501b0c3354b7b182abc0
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.9 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 --opt
 | 
						|
 | 
						|
function TestSetWithCustomIterator(ctor) {
 | 
						|
  const k1 = {};
 | 
						|
  const k2 = {};
 | 
						|
  const entries = [k1];
 | 
						|
  let callCount = 0;
 | 
						|
  entries[Symbol.iterator] = () => ({
 | 
						|
    next: () =>
 | 
						|
      callCount++ === 0
 | 
						|
        ? { value: k2, done: false }
 | 
						|
        : { done: true }
 | 
						|
  });
 | 
						|
  const set = new ctor(entries);
 | 
						|
  assertFalse(set.has(k1));
 | 
						|
  assertTrue(set.has(k2));
 | 
						|
  assertEquals(2, callCount);
 | 
						|
}
 | 
						|
TestSetWithCustomIterator(Set);
 | 
						|
TestSetWithCustomIterator(Set);
 | 
						|
TestSetWithCustomIterator(Set);
 | 
						|
%OptimizeFunctionOnNextCall(TestSetWithCustomIterator);
 | 
						|
TestSetWithCustomIterator(Set);
 | 
						|
assertOptimized(TestSetWithCustomIterator);
 | 
						|
 | 
						|
TestSetWithCustomIterator(WeakSet);
 | 
						|
TestSetWithCustomIterator(WeakSet);
 | 
						|
TestSetWithCustomIterator(WeakSet);
 | 
						|
%OptimizeFunctionOnNextCall(TestSetWithCustomIterator);
 | 
						|
TestSetWithCustomIterator(WeakSet);
 | 
						|
assertOptimized(TestSetWithCustomIterator);
 | 
						|
 | 
						|
function TestMapWithCustomIterator(ctor) {
 | 
						|
  const k1 = {};
 | 
						|
  const k2 = {};
 | 
						|
  const entries = [[k1, 1]];
 | 
						|
  let callCount = 0;
 | 
						|
  entries[Symbol.iterator] = () => ({
 | 
						|
    next: () =>
 | 
						|
      callCount++ === 0
 | 
						|
        ? { value: [k2, 2], done: false }
 | 
						|
        : { done: true }
 | 
						|
  });
 | 
						|
  const map = new ctor(entries);
 | 
						|
  assertFalse(map.has(k1));
 | 
						|
  assertEquals(2, map.get(k2));
 | 
						|
  assertEquals(2, callCount);
 | 
						|
}
 | 
						|
TestMapWithCustomIterator(Map);
 | 
						|
TestMapWithCustomIterator(Map);
 | 
						|
TestMapWithCustomIterator(Map);
 | 
						|
%OptimizeFunctionOnNextCall(TestMapWithCustomIterator);
 | 
						|
TestMapWithCustomIterator(Map);
 | 
						|
assertOptimized(TestMapWithCustomIterator);
 | 
						|
 | 
						|
TestMapWithCustomIterator(WeakMap);
 | 
						|
TestMapWithCustomIterator(WeakMap);
 | 
						|
TestMapWithCustomIterator(WeakMap);
 | 
						|
%OptimizeFunctionOnNextCall(TestMapWithCustomIterator);
 | 
						|
TestMapWithCustomIterator(WeakMap);
 | 
						|
assertOptimized(TestMapWithCustomIterator);
 |