debug-evaluate-repl-mode-optimized.js 1.57 KB
Newer Older
Simon Zünd's avatar
Simon Zünd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// Copyright 2019 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: --opt

Debug = debug.Debug

const evaluate = Debug.evaluateGlobalREPL;
const evaluateNonREPL = (source) => Debug.evaluateGlobal(source, false).value();

// Test that a let declared variable 'x' bound by an optimized function is
// updated properly.
evaluate('let x = 42;');

evaluate('function foo() { return x; }');

%PrepareFunctionForOptimization(foo);
foo();
foo();
%OptimizeFunctionOnNextCall(foo);
assertEquals(42, foo());
assertOptimized(foo);

evaluate('let x = 21');
assertEquals(21, foo());

// Test that we do not throw a 'use before declaration error' and
// that the optimized code does not load the hole from the wrong
// script context.
evaluate('x; let x;');
assertEquals(undefined, foo());
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

// Test that a const declared variable 'y' bound by an optimized function is
// updated properly.
evaluate('const y = 42;');

evaluate('function foo1() { return y; }');

%PrepareFunctionForOptimization(foo1);
foo1();
foo1();
%OptimizeFunctionOnNextCall(foo1);
assertEquals(42, foo1());
assertOptimized(foo1);

evaluate('const y = 21');
assertEquals(21, foo1());

// Test that a const declared variable 'z' bound by an optimized function is
// updated properly.
evaluate('const z = {a:0};');

evaluate('function foo2() { z.a = 42; }');

%PrepareFunctionForOptimization(foo2);
foo2();
foo2();
%OptimizeFunctionOnNextCall(foo2);
foo2();
assertOptimized(foo2);

evaluate('const z = {a:21}');
foo2();
assertEquals(42, z.a);