v8/test/mjsunit/compiler/serializer-accessors.js
Georg Neis 9ac62c4dcc Introduce %IsBeingInterpreted
A call to this intrinsic will produce true in the interpreter and false
in optimized code. This is useful for writing tests.

Change-Id: I64d06ed062027e723eca82d6f879202244f21fdf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1939750
Commit-Queue: Georg Neis <neis@chromium.org>
Auto-Submit: Georg Neis <neis@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65240}
2019-11-28 14:20:45 +00:00

38 lines
889 B
JavaScript

// 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: --allow-natives-syntax --opt --no-always-opt
var expect_interpreted = true;
class C {
get prop() {
return 42;
}
set prop(v) {
assertEquals(expect_interpreted, %IsBeingInterpreted());
%TurbofanStaticAssert(v === 43);
}
}
const c = new C();
function foo() {
assertEquals(expect_interpreted, %IsBeingInterpreted());
%TurbofanStaticAssert(c.prop === 42);
c.prop = 43;
}
%PrepareFunctionForOptimization(
Object.getOwnPropertyDescriptor(C.prototype, 'prop').get);
%PrepareFunctionForOptimization(
Object.getOwnPropertyDescriptor(C.prototype, 'prop').set);
%PrepareFunctionForOptimization(foo);
foo();
foo();
%OptimizeFunctionOnNextCall(foo);
expect_interpreted = false;
foo();