OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <tuple> | 5 #include <tuple> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/execution.h" | 9 #include "src/execution.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 isolate->factory()->NewHeapNumber(Smi::kMaxValue + 1.0), | 548 isolate->factory()->NewHeapNumber(Smi::kMaxValue + 1.0), |
549 BinaryOperationFeedback::kNumber}, | 549 BinaryOperationFeedback::kNumber}, |
550 {Token::Value::ADD, isolate->factory()->NewHeapNumber(3.1415), | 550 {Token::Value::ADD, isolate->factory()->NewHeapNumber(3.1415), |
551 Handle<Smi>(Smi::FromInt(3), isolate), | 551 Handle<Smi>(Smi::FromInt(3), isolate), |
552 isolate->factory()->NewHeapNumber(3.1415 + 3), | 552 isolate->factory()->NewHeapNumber(3.1415 + 3), |
553 BinaryOperationFeedback::kNumber}, | 553 BinaryOperationFeedback::kNumber}, |
554 {Token::Value::ADD, isolate->factory()->NewHeapNumber(3.1415), | 554 {Token::Value::ADD, isolate->factory()->NewHeapNumber(3.1415), |
555 isolate->factory()->NewHeapNumber(1.4142), | 555 isolate->factory()->NewHeapNumber(1.4142), |
556 isolate->factory()->NewHeapNumber(3.1415 + 1.4142), | 556 isolate->factory()->NewHeapNumber(3.1415 + 1.4142), |
557 BinaryOperationFeedback::kNumber}, | 557 BinaryOperationFeedback::kNumber}, |
| 558 {Token::Value::ADD, isolate->factory()->NewStringFromAsciiChecked("foo"), |
| 559 isolate->factory()->NewStringFromAsciiChecked("bar"), |
| 560 isolate->factory()->NewStringFromAsciiChecked("foobar"), |
| 561 BinaryOperationFeedback::kString}, |
558 {Token::Value::ADD, Handle<Smi>(Smi::FromInt(2), isolate), | 562 {Token::Value::ADD, Handle<Smi>(Smi::FromInt(2), isolate), |
559 isolate->factory()->NewStringFromAsciiChecked("2"), | 563 isolate->factory()->NewStringFromAsciiChecked("2"), |
560 isolate->factory()->NewStringFromAsciiChecked("22"), | 564 isolate->factory()->NewStringFromAsciiChecked("22"), |
561 BinaryOperationFeedback::kAny}, | 565 BinaryOperationFeedback::kAny}, |
562 // SUB | 566 // SUB |
563 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(2), isolate), | 567 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(2), isolate), |
564 Handle<Smi>(Smi::FromInt(3), isolate), | 568 Handle<Smi>(Smi::FromInt(3), isolate), |
565 Handle<Smi>(Smi::FromInt(-1), isolate), | 569 Handle<Smi>(Smi::FromInt(-1), isolate), |
566 BinaryOperationFeedback::kSignedSmall}, | 570 BinaryOperationFeedback::kSignedSmall}, |
567 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(Smi::kMinValue), isolate), | 571 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(Smi::kMinValue), isolate), |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 | 1806 |
1803 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); | 1807 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1804 InterpreterTester tester(isolate, bytecode_array, vector); | 1808 InterpreterTester tester(isolate, bytecode_array, vector); |
1805 auto callable = tester.GetCallable<>(); | 1809 auto callable = tester.GetCallable<>(); |
1806 Handle<Object> return_value = callable().ToHandleChecked(); | 1810 Handle<Object> return_value = callable().ToHandleChecked(); |
1807 CHECK(return_value->IsBoolean()); | 1811 CHECK(return_value->IsBoolean()); |
1808 CHECK_EQ(return_value->BooleanValue(), | 1812 CHECK_EQ(return_value->BooleanValue(), |
1809 CompareC(comparison, inputs[i], inputs[j])); | 1813 CompareC(comparison, inputs[i], inputs[j])); |
1810 Object* feedback = vector->Get(slot); | 1814 Object* feedback = vector->Get(slot); |
1811 CHECK(feedback->IsSmi()); | 1815 CHECK(feedback->IsSmi()); |
1812 CHECK_EQ(CompareOperationFeedback::kAny, | 1816 CHECK_EQ(CompareOperationFeedback::kString, |
1813 static_cast<Smi*>(feedback)->value()); | 1817 static_cast<Smi*>(feedback)->value()); |
1814 } | 1818 } |
1815 } | 1819 } |
1816 } | 1820 } |
1817 } | 1821 } |
1818 | 1822 |
1819 | 1823 |
1820 TEST(InterpreterMixedComparisons) { | 1824 TEST(InterpreterMixedComparisons) { |
1821 // This test compares a HeapNumber with a String. The latter is | 1825 // This test compares a HeapNumber with a String. The latter is |
1822 // convertible to a HeapNumber so comparison will be between numeric | 1826 // convertible to a HeapNumber so comparison will be between numeric |
1823 // values except for the strict comparisons where no conversion is | 1827 // values except for the strict comparisons where no conversion is |
1824 // performed. | 1828 // performed. |
1825 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; | 1829 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e50", "2.01"}; |
1826 | 1830 |
1827 UnicodeCache unicode_cache; | 1831 UnicodeCache unicode_cache; |
1828 | 1832 |
1829 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1833 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1830 Token::Value comparison = kComparisonTypes[c]; | 1834 Token::Value comparison = kComparisonTypes[c]; |
1831 for (size_t i = 0; i < arraysize(inputs); i++) { | 1835 for (size_t i = 0; i < arraysize(inputs); i++) { |
1832 for (size_t j = 0; j < arraysize(inputs); j++) { | 1836 for (size_t j = 0; j < arraysize(inputs); j++) { |
1833 for (int pass = 0; pass < 2; pass++) { | 1837 for (int pass = 0; pass < 2; pass++) { |
1834 const char* lhs_cstr = inputs[i]; | 1838 const char* lhs_cstr = inputs[i]; |
1835 const char* rhs_cstr = inputs[j]; | 1839 const char* rhs_cstr = inputs[j]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 Handle<BytecodeArray> bytecode_array = | 1872 Handle<BytecodeArray> bytecode_array = |
1869 builder.ToBytecodeArray(isolate); | 1873 builder.ToBytecodeArray(isolate); |
1870 InterpreterTester tester(isolate, bytecode_array, vector); | 1874 InterpreterTester tester(isolate, bytecode_array, vector); |
1871 auto callable = tester.GetCallable<>(); | 1875 auto callable = tester.GetCallable<>(); |
1872 Handle<Object> return_value = callable().ToHandleChecked(); | 1876 Handle<Object> return_value = callable().ToHandleChecked(); |
1873 CHECK(return_value->IsBoolean()); | 1877 CHECK(return_value->IsBoolean()); |
1874 CHECK_EQ(return_value->BooleanValue(), | 1878 CHECK_EQ(return_value->BooleanValue(), |
1875 CompareC(comparison, lhs, rhs, true)); | 1879 CompareC(comparison, lhs, rhs, true)); |
1876 Object* feedback = vector->Get(slot); | 1880 Object* feedback = vector->Get(slot); |
1877 CHECK(feedback->IsSmi()); | 1881 CHECK(feedback->IsSmi()); |
1878 CHECK_EQ(CompareOperationFeedback::kAny, | 1882 // kNumber | kString gets converted to CompareOperationHint::kAny. |
1879 static_cast<Smi*>(feedback)->value()); | 1883 int expected_feedback = CompareOperationFeedback::kNumber | |
| 1884 CompareOperationFeedback::kString; |
| 1885 CHECK_EQ(expected_feedback, static_cast<Smi*>(feedback)->value()); |
1880 } | 1886 } |
1881 } | 1887 } |
1882 } | 1888 } |
1883 } | 1889 } |
1884 } | 1890 } |
1885 | 1891 |
1886 TEST(InterpreterStrictNotEqual) { | 1892 TEST(InterpreterStrictNotEqual) { |
1887 HandleAndZoneScope handles; | 1893 HandleAndZoneScope handles; |
1888 Isolate* isolate = handles.main_isolate(); | 1894 Isolate* isolate = handles.main_isolate(); |
1889 Factory* factory = isolate->factory(); | 1895 Factory* factory = isolate->factory(); |
(...skipping 2931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4821 auto callable = tester.GetCallable<>(); | 4827 auto callable = tester.GetCallable<>(); |
4822 | 4828 |
4823 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4829 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4824 CHECK(return_value->SameValue(*tests[i].second)); | 4830 CHECK(return_value->SameValue(*tests[i].second)); |
4825 } | 4831 } |
4826 } | 4832 } |
4827 | 4833 |
4828 } // namespace interpreter | 4834 } // namespace interpreter |
4829 } // namespace internal | 4835 } // namespace internal |
4830 } // namespace v8 | 4836 } // namespace v8 |
OLD | NEW |