v8/test/mjsunit/undetectable.js
Maya Lekova 7f50476b83 [builtins] Introduce CallProxy builtin based on CSA
- Add more conformance tests for proxy call and calling undetectable
- This improves the performance of calling a proxy by ~5x

Bug: v8:6558, v8:6557
Change-Id: I5fe78d7ca703cfe86a2a14e39f0b6d88bb8c8e03
Reviewed-on: https://chromium-review.googlesource.com/570023
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Maya Lekova <mslekova@google.com>
Cr-Commit-Position: refs/heads/master@{#46673}
2017-07-14 11:22:48 +00:00

94 lines
1.6 KiB
JavaScript

// Copyright 2015 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
var obj = %GetUndetectable();
function shouldNotBeTaken() {
fail("Undetectable branch should not be taken", "branch was taken");
}
function shouldBeTaken() {
fail("Inverted Undetectable branch should be taken", "branch was not taken");
}
function testCompares() {
assertTrue(!obj);
assertFalse(!!obj);
assertFalse(obj == true);
assertFalse(obj == false);
assertFalse(obj === true);
assertFalse(obj === false);
assertEquals(2, obj ? 1 : 2);
assertEquals(obj, true && obj);
assertEquals(obj, false || obj);
}
function testIfs() {
if (obj) {
shouldNotBeTaken();
}
if (obj) {
shouldNotBeTaken();
} else {
// do nothing
}
if (!obj) {
// do nothing
} else {
shouldBeTaken();
}
}
function testWhiles() {
while (obj) {
shouldNotBeTaken();
}
var i = 0;
while (!obj) {
i++;
break;
}
assertEquals(1, i);
}
function testFors() {
for (var i = 0; obj; i++) {
shouldNotBeTaken();
}
var j = 0;
for (var i = 0; !obj; i++) {
j++;
break;
}
assertEquals(1, j);
}
function testCall() {
obj();
}
for (var j = 0; j < 5; j++) {
testCompares();
testIfs();
testWhiles();
testFors();
testCall();
if (j == 3) {
%OptimizeFunctionOnNextCall(testCompares);
%OptimizeFunctionOnNextCall(testIfs);
%OptimizeFunctionOnNextCall(testWhiles);
%OptimizeFunctionOnNextCall(testFors);
%OptimizeFunctionOnNextCall(testCall);
}
}