Commit f750cc09 authored by titzer's avatar titzer Committed by Commit bot

Add %GetUndetectable() test intrinsic and add tests for undetectables.

R=verwaest@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1132303003

Cr-Commit-Position: refs/heads/master@{#28338}
parent 004bb77e
......@@ -212,6 +212,18 @@ RUNTIME_FUNCTION(Runtime_GetOptimizationCount) {
}
RUNTIME_FUNCTION(Runtime_GetUndetectable) {
HandleScope scope(isolate);
DCHECK(args.length() == 0);
Local<v8::ObjectTemplate> desc =
v8::ObjectTemplate::New((v8::Isolate*)isolate);
desc->MarkAsUndetectable(); // undetectable
Local<v8::Object> obj = desc->NewInstance();
return *Utils::OpenHandle(*obj);
}
RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
......
......@@ -581,6 +581,7 @@ namespace internal {
F(GetOptimizationStatus, -1, 1) \
F(UnblockConcurrentRecompilation, 0, 1) \
F(GetOptimizationCount, 1, 1) \
F(GetUndetectable, 0, 1) \
F(ClearFunctionTypeFeedback, 1, 1) \
F(NotifyContextDisposed, 0, 1) \
F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
......
// 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 undetectable = %GetUndetectable();
var tests = [
true, false,
false, false,
null, true,
void 0, true,
0, false,
0.0, false,
-0, false,
"", false,
-1, false,
-1.25, false,
1, false,
1.25, false,
-2147483648, false,
2147483648, false,
Infinity, false,
-Infinity, false,
NaN, false
];
var func = (function eq(a) { return a == undetectable; });
var left_funcs = [
(function eq_L0() { return true == undetectable; }),
(function eq_L1() { return false == undetectable; }),
(function eq_L2() { return null == undetectable; }),
(function eq_L3() { return void 0 == undetectable; }),
(function eq_L4() { return 0 == undetectable; }),
(function eq_L5() { return 0.0 == undetectable; }),
(function eq_L6() { return -0 == undetectable; }),
(function eq_L7() { return "" == undetectable; }),
(function eq_L8() { return -1 == undetectable; }),
(function eq_L9() { return -1.25 == undetectable; }),
(function eq_L10() { return 1 == undetectable; }),
(function eq_L11() { return 1.25 == undetectable; }),
(function eq_L12() { return -2147483648 == undetectable; }),
(function eq_L13() { return 2147483648 == undetectable; }),
(function eq_L14() { return Infinity == undetectable; }),
(function eq_L15() { return -Infinity == undetectable; }),
(function eq_L16() { return NaN == undetectable; })
];
var right_funcs = [
(function eq_R0() { return undetectable == true; }),
(function eq_R1() { return undetectable == false; }),
(function eq_R2() { return undetectable == null; }),
(function eq_R3() { return undetectable == void 0; }),
(function eq_R4() { return undetectable == 0; }),
(function eq_R5() { return undetectable == 0.0; }),
(function eq_R6() { return undetectable == -0; }),
(function eq_R7() { return undetectable == ""; }),
(function eq_R8() { return undetectable == -1; }),
(function eq_R9() { return undetectable == -1.25; }),
(function eq_R10() { return undetectable == 1; }),
(function eq_R11() { return undetectable == 1.25; }),
(function eq_R12() { return undetectable == -2147483648; }),
(function eq_R13() { return undetectable == 2147483648; }),
(function eq_R14() { return undetectable == Infinity; }),
(function eq_R15() { return undetectable == -Infinity; }),
(function eq_R16() { return undetectable == NaN; })
];
function test() {
for (var i = 0; i < tests.length; i += 2) {
var val = tests[i];
var eq = tests[i + 1];
assertEquals(eq, val == undetectable);
assertEquals(eq, undetectable == val);
assertFalse(val === undetectable);
assertFalse(undetectable === val);
assertEquals(eq, left_funcs[i/2]());
assertEquals(eq, right_funcs[i/2]());
}
assertTrue(undetectable == undetectable);
assertTrue(undetectable === undetectable);
}
for (var i = 0; i < 5; i++) {
test();
}
assertFalse(undetectable == %GetUndetectable());
assertFalse(undetectable === %GetUndetectable());
// 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);
}
for (var j = 0; j < 5; j++) {
testCompares();
testIfs();
testWhiles();
testFors();
if (j == 3) {
%OptimizeFunctionOnNextCall(testCompares);
%OptimizeFunctionOnNextCall(testIfs);
%OptimizeFunctionOnNextCall(testWhiles);
%OptimizeFunctionOnNextCall(testFors);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment