v8/test/mjsunit/maglev/undefined-or-null-branch.js
jameslahm 5903aa9354 [maglev] Support JumpIfUndefinedOrNull
Bug: v8:7700
Change-Id: I36018a3323d778b8657087736e1bff70b0fdbf2d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3779920
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82145}
2022-08-02 15:10:13 +00:00

20 lines
562 B
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 --maglev --no-stress-opt --no-always-turbofan
function foo(x) {
return x ?? 10
}
%PrepareFunctionForOptimization(foo);
assertEquals(10, foo(undefined));
assertEquals(10, foo(null));
assertEquals(1, foo(1));
%OptimizeMaglevOnNextCall(foo);
assertEquals(10, foo(undefined));
assertEquals(10, foo(null));
assertEquals(1, foo(1));
assertTrue(isMaglevved(foo));