v8/test/mjsunit/maglev/mutable-context-access.js
Leszek Swirski 88976125a6 [maglev] Implement LdaContextSlot
In the simplest way possible.

Bug: v8:7700
Change-Id: I155aaf85192b75c89617820d6f127a2ae04c7d9b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3599484
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80089}
2022-04-21 16:06:15 +00:00

46 lines
902 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
function factory() {
var x = 1;
x = 2;
return function foo() {
return x;
}
}
let foo = factory();
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo());
assertEquals(2, foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals(2, foo());
function nested_factory() {
var x = 1;
x = 2;
return (function() {
var z = 3;
return function foo(){
// Add two values from different contexts to force an
// LdaImmutableCurrentContextSlot
return x+z;
}
})();
}
foo = nested_factory();
%PrepareFunctionForOptimization(foo);
assertEquals(5, foo());
assertEquals(5, foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals(5, foo());