OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/compiler/graph-inl.h" | 8 #include "src/compiler/graph-inl.h" |
9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 { // ToBoolean(object) | 499 { // ToBoolean(object) |
500 Node* r = R.ReduceUnop(op, Type::Object()); | 500 Node* r = R.ReduceUnop(op, Type::Object()); |
501 CHECK_EQ(IrOpcode::kJSToBoolean, r->opcode()); | 501 CHECK_EQ(IrOpcode::kJSToBoolean, r->opcode()); |
502 } | 502 } |
503 } | 503 } |
504 | 504 |
505 | 505 |
506 TEST(JSToBoolean_replacement) { | 506 TEST(JSToBoolean_replacement) { |
507 JSTypedLoweringTester R; | 507 JSTypedLoweringTester R; |
508 | 508 |
509 Type* types[] = {Type::Null(), Type::Undefined(), Type::Boolean(), | 509 Type* types[] = {Type::Null(), Type::Undefined(), |
510 Type::Boolean(), Type::Number(), | |
510 Type::DetectableObject(), Type::Undetectable()}; | 511 Type::DetectableObject(), Type::Undetectable()}; |
511 | 512 |
512 for (size_t i = 0; i < arraysize(types); i++) { | 513 for (size_t i = 0; i < arraysize(types); i++) { |
513 Node* n = R.Parameter(types[i]); | 514 Node* n = R.Parameter(types[i]); |
514 Node* c = R.graph.NewNode(R.javascript.ToBoolean(), n, R.context(), | 515 Node* c = R.graph.NewNode(R.javascript.ToBoolean(), n, R.context(), |
515 R.start(), R.start()); | 516 R.start(), R.start()); |
516 Node* effect_use = R.UseForEffect(c); | 517 Node* effect_use = R.UseForEffect(c); |
517 Node* add = R.graph.NewNode(R.simplified.ReferenceEqual(Type::Any()), n, c); | 518 Node* add = R.graph.NewNode(R.simplified.ReferenceEqual(Type::Any()), n, c); |
518 | 519 |
519 R.CheckEffectInput(c, effect_use); | 520 R.CheckEffectInput(c, effect_use); |
520 Node* r = R.reduce(c); | 521 Node* r = R.reduce(c); |
521 | 522 |
522 if (types[i]->Is(Type::Boolean())) { | 523 if (types[i]->Is(Type::Boolean())) { |
523 CHECK_EQ(n, r); | 524 CHECK_EQ(n, r); |
525 } else if (types[i]->Is(Type::Number())) { | |
526 CHECK_EQ(IrOpcode::kBooleanNot, r->opcode()); | |
titzer
2014/09/03 11:24:49
Check it's actually BooleanNot(NumberEqual(x, 0))
Michael Starzinger
2014/09/03 11:33:00
As discussed offline: This is already checked in t
| |
524 } else { | 527 } else { |
525 CHECK_EQ(IrOpcode::kHeapConstant, r->opcode()); | 528 CHECK_EQ(IrOpcode::kHeapConstant, r->opcode()); |
526 } | 529 } |
527 | 530 |
528 CHECK_EQ(n, add->InputAt(0)); | 531 CHECK_EQ(n, add->InputAt(0)); |
529 CHECK_EQ(r, add->InputAt(1)); | 532 CHECK_EQ(r, add->InputAt(1)); |
530 R.CheckEffectInput(R.start(), effect_use); | 533 R.CheckEffectInput(R.start(), effect_use); |
531 } | 534 } |
532 } | 535 } |
533 | 536 |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 CHECK_EQ(p1, r->InputAt(0)); | 1343 CHECK_EQ(p1, r->InputAt(0)); |
1341 CHECK_EQ(p0, r->InputAt(1)); | 1344 CHECK_EQ(p0, r->InputAt(1)); |
1342 } else { | 1345 } else { |
1343 CHECK_EQ(p0, r->InputAt(0)); | 1346 CHECK_EQ(p0, r->InputAt(0)); |
1344 CHECK_EQ(p1, r->InputAt(1)); | 1347 CHECK_EQ(p1, r->InputAt(1)); |
1345 } | 1348 } |
1346 } | 1349 } |
1347 } | 1350 } |
1348 } | 1351 } |
1349 } | 1352 } |
OLD | NEW |