mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 17:23:43 +00:00

PR-URL: https://github.com/nodejs/node/pull/44741 Fixes: https://github.com/nodejs/node/issues/44650 Fixes: https://github.com/nodejs/node/issues/37472 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
78 lines
1.4 KiB
JavaScript
78 lines
1.4 KiB
JavaScript
// Copyright 2022 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() {
|
|
const map = new Map();
|
|
map.set(true, true);
|
|
|
|
for (let i = 0; i < 10000; i += 1) {
|
|
map.set(i, i);
|
|
map.set(`${i} number`, i);
|
|
}
|
|
|
|
function foo(x) {
|
|
return map.has(x);
|
|
}
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertFalse(foo(1.5));
|
|
assertTrue(foo(1));
|
|
|
|
assertFalse(foo('1.5 number'));
|
|
assertTrue(foo('1 number'));
|
|
|
|
assertFalse(foo(false));
|
|
assertTrue(foo(true));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertFalse(foo(1.5));
|
|
assertTrue(foo(1));
|
|
|
|
assertFalse(foo('1.5 number'));
|
|
assertTrue(foo('1 number'));
|
|
|
|
assertFalse(foo(false));
|
|
assertTrue(foo(true));
|
|
})();
|
|
|
|
(function() {
|
|
const set = new Set();
|
|
set.add(true);
|
|
|
|
for (let i = 0; i < 10000; i += 1) {
|
|
set.add(i);
|
|
set.add(`${i} number`);
|
|
}
|
|
|
|
function foo(x) {
|
|
return set.has(x);
|
|
}
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertFalse(foo(1.5));
|
|
assertTrue(foo(1));
|
|
|
|
assertFalse(foo('1.5 number'));
|
|
assertTrue(foo('1 number'));
|
|
|
|
assertFalse(foo(false));
|
|
assertTrue(foo(true));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertFalse(foo(1.5));
|
|
assertTrue(foo(1));
|
|
|
|
assertFalse(foo('1.5 number'));
|
|
assertTrue(foo('1 number'));
|
|
|
|
assertFalse(foo(false));
|
|
assertTrue(foo(true));
|
|
})();
|