| 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 <functional> | 5 #include <functional> |
| 6 | 6 |
| 7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 10 #include "test/cctest/types-fuzz.h" | 10 #include "test/cctest/types-fuzz.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 | 219 |
| 220 //------------------------------------------------------------------------------ | 220 //------------------------------------------------------------------------------ |
| 221 // Soundness | 221 // Soundness |
| 222 // For simplicity, we currently only test soundness on expression operators | 222 // For simplicity, we currently only test soundness on expression operators |
| 223 // that have a direct equivalent in C++. Also, testing is currently limited | 223 // that have a direct equivalent in C++. Also, testing is currently limited |
| 224 // to ranges as input types. | 224 // to ranges as input types. |
| 225 | 225 |
| 226 | 226 |
| 227 TEST_F(TyperTest, TypeJSAdd) { | 227 TEST_F(TyperTest, TypeJSAdd) { |
| 228 TestBinaryArithOp(javascript_.Add(LanguageMode::SLOPPY), std::plus<double>()); | 228 TestBinaryArithOp(javascript_.Add(Strength::WEAK), std::plus<double>()); |
| 229 TestBinaryArithOp(javascript_.Add(LanguageMode::STRONG), std::plus<double>()); | 229 TestBinaryArithOp(javascript_.Add(Strength::FIRM), std::plus<double>()); |
| 230 } | 230 } |
| 231 | 231 |
| 232 | 232 |
| 233 TEST_F(TyperTest, TypeJSSubtract) { | 233 TEST_F(TyperTest, TypeJSSubtract) { |
| 234 TestBinaryArithOp(javascript_.Subtract(LanguageMode::SLOPPY), | 234 TestBinaryArithOp(javascript_.Subtract(Strength::WEAK), std::minus<double>()); |
| 235 std::minus<double>()); | 235 TestBinaryArithOp(javascript_.Subtract(Strength::FIRM), std::minus<double>()); |
| 236 TestBinaryArithOp(javascript_.Subtract(LanguageMode::STRONG), | |
| 237 std::minus<double>()); | |
| 238 } | 236 } |
| 239 | 237 |
| 240 | 238 |
| 241 TEST_F(TyperTest, TypeJSMultiply) { | 239 TEST_F(TyperTest, TypeJSMultiply) { |
| 242 TestBinaryArithOp(javascript_.Multiply(LanguageMode::SLOPPY), | 240 TestBinaryArithOp(javascript_.Multiply(Strength::WEAK), |
| 243 std::multiplies<double>()); | 241 std::multiplies<double>()); |
| 244 TestBinaryArithOp(javascript_.Multiply(LanguageMode::STRONG), | 242 TestBinaryArithOp(javascript_.Multiply(Strength::FIRM), |
| 245 std::multiplies<double>()); | 243 std::multiplies<double>()); |
| 246 } | 244 } |
| 247 | 245 |
| 248 | 246 |
| 249 TEST_F(TyperTest, TypeJSDivide) { | 247 TEST_F(TyperTest, TypeJSDivide) { |
| 250 TestBinaryArithOp(javascript_.Divide(LanguageMode::SLOPPY), | 248 TestBinaryArithOp(javascript_.Divide(Strength::WEAK), std::divides<double>()); |
| 251 std::divides<double>()); | 249 TestBinaryArithOp(javascript_.Divide(Strength::FIRM), std::divides<double>()); |
| 252 TestBinaryArithOp(javascript_.Divide(LanguageMode::STRONG), | |
| 253 std::divides<double>()); | |
| 254 } | 250 } |
| 255 | 251 |
| 256 | 252 |
| 257 TEST_F(TyperTest, TypeJSModulus) { | 253 TEST_F(TyperTest, TypeJSModulus) { |
| 258 TestBinaryArithOp(javascript_.Modulus(LanguageMode::SLOPPY), modulo); | 254 TestBinaryArithOp(javascript_.Modulus(Strength::WEAK), modulo); |
| 259 TestBinaryArithOp(javascript_.Modulus(LanguageMode::STRONG), modulo); | 255 TestBinaryArithOp(javascript_.Modulus(Strength::FIRM), modulo); |
| 260 } | 256 } |
| 261 | 257 |
| 262 | 258 |
| 263 TEST_F(TyperTest, TypeJSBitwiseOr) { | 259 TEST_F(TyperTest, TypeJSBitwiseOr) { |
| 264 TestBinaryBitOp(javascript_.BitwiseOr(LanguageMode::SLOPPY), bit_or); | 260 TestBinaryBitOp(javascript_.BitwiseOr(Strength::WEAK), bit_or); |
| 265 TestBinaryBitOp(javascript_.BitwiseOr(LanguageMode::STRONG), bit_or); | 261 TestBinaryBitOp(javascript_.BitwiseOr(Strength::FIRM), bit_or); |
| 266 } | 262 } |
| 267 | 263 |
| 268 | 264 |
| 269 TEST_F(TyperTest, TypeJSBitwiseAnd) { | 265 TEST_F(TyperTest, TypeJSBitwiseAnd) { |
| 270 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::SLOPPY), bit_and); | 266 TestBinaryBitOp(javascript_.BitwiseAnd(Strength::WEAK), bit_and); |
| 271 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::STRONG), bit_and); | 267 TestBinaryBitOp(javascript_.BitwiseAnd(Strength::FIRM), bit_and); |
| 272 } | 268 } |
| 273 | 269 |
| 274 | 270 |
| 275 TEST_F(TyperTest, TypeJSBitwiseXor) { | 271 TEST_F(TyperTest, TypeJSBitwiseXor) { |
| 276 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::SLOPPY), bit_xor); | 272 TestBinaryBitOp(javascript_.BitwiseXor(Strength::WEAK), bit_xor); |
| 277 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::STRONG), bit_xor); | 273 TestBinaryBitOp(javascript_.BitwiseXor(Strength::FIRM), bit_xor); |
| 278 } | 274 } |
| 279 | 275 |
| 280 | 276 |
| 281 TEST_F(TyperTest, TypeJSShiftLeft) { | 277 TEST_F(TyperTest, TypeJSShiftLeft) { |
| 282 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); | 278 TestBinaryBitOp(javascript_.ShiftLeft(Strength::WEAK), shift_left); |
| 283 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); | 279 TestBinaryBitOp(javascript_.ShiftLeft(Strength::FIRM), shift_left); |
| 284 } | 280 } |
| 285 | 281 |
| 286 | 282 |
| 287 TEST_F(TyperTest, TypeJSShiftRight) { | 283 TEST_F(TyperTest, TypeJSShiftRight) { |
| 288 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right); | 284 TestBinaryBitOp(javascript_.ShiftRight(Strength::WEAK), shift_right); |
| 289 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right); | 285 TestBinaryBitOp(javascript_.ShiftRight(Strength::FIRM), shift_right); |
| 290 } | 286 } |
| 291 | 287 |
| 292 | 288 |
| 293 TEST_F(TyperTest, TypeJSLessThan) { | 289 TEST_F(TyperTest, TypeJSLessThan) { |
| 294 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::SLOPPY), | 290 TestBinaryCompareOp(javascript_.LessThan(Strength::WEAK), |
| 295 std::less<double>()); | 291 std::less<double>()); |
| 296 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::STRONG), | 292 TestBinaryCompareOp(javascript_.LessThan(Strength::FIRM), |
| 297 std::less<double>()); | 293 std::less<double>()); |
| 298 } | 294 } |
| 299 | 295 |
| 300 | 296 |
| 301 TEST_F(TyperTest, TypeJSLessThanOrEqual) { | 297 TEST_F(TyperTest, TypeJSLessThanOrEqual) { |
| 302 TestBinaryCompareOp(javascript_.LessThanOrEqual(LanguageMode::SLOPPY), | 298 TestBinaryCompareOp(javascript_.LessThanOrEqual(Strength::WEAK), |
| 303 std::less_equal<double>()); | 299 std::less_equal<double>()); |
| 304 TestBinaryCompareOp(javascript_.LessThanOrEqual(LanguageMode::STRONG), | 300 TestBinaryCompareOp(javascript_.LessThanOrEqual(Strength::FIRM), |
| 305 std::less_equal<double>()); | 301 std::less_equal<double>()); |
| 306 } | 302 } |
| 307 | 303 |
| 308 | 304 |
| 309 TEST_F(TyperTest, TypeJSGreaterThan) { | 305 TEST_F(TyperTest, TypeJSGreaterThan) { |
| 310 TestBinaryCompareOp(javascript_.GreaterThan(LanguageMode::SLOPPY), | 306 TestBinaryCompareOp(javascript_.GreaterThan(Strength::WEAK), |
| 311 std::greater<double>()); | 307 std::greater<double>()); |
| 312 TestBinaryCompareOp(javascript_.GreaterThan(LanguageMode::STRONG), | 308 TestBinaryCompareOp(javascript_.GreaterThan(Strength::FIRM), |
| 313 std::greater<double>()); | 309 std::greater<double>()); |
| 314 } | 310 } |
| 315 | 311 |
| 316 | 312 |
| 317 TEST_F(TyperTest, TypeJSGreaterThanOrEqual) { | 313 TEST_F(TyperTest, TypeJSGreaterThanOrEqual) { |
| 318 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(LanguageMode::SLOPPY), | 314 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(Strength::WEAK), |
| 319 std::greater_equal<double>()); | 315 std::greater_equal<double>()); |
| 320 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(LanguageMode::STRONG), | 316 TestBinaryCompareOp(javascript_.GreaterThanOrEqual(Strength::FIRM), |
| 321 std::greater_equal<double>()); | 317 std::greater_equal<double>()); |
| 322 } | 318 } |
| 323 | 319 |
| 324 | 320 |
| 325 TEST_F(TyperTest, TypeJSEqual) { | 321 TEST_F(TyperTest, TypeJSEqual) { |
| 326 TestBinaryCompareOp(javascript_.Equal(), std::equal_to<double>()); | 322 TestBinaryCompareOp(javascript_.Equal(), std::equal_to<double>()); |
| 327 } | 323 } |
| 328 | 324 |
| 329 | 325 |
| 330 TEST_F(TyperTest, TypeJSNotEqual) { | 326 TEST_F(TyperTest, TypeJSNotEqual) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 371 |
| 376 | 372 |
| 377 #define TEST_FUNC(name) \ | 373 #define TEST_FUNC(name) \ |
| 378 TEST_F(TyperTest, Monotonicity_##name) { \ | 374 TEST_F(TyperTest, Monotonicity_##name) { \ |
| 379 TestBinaryMonotonicity(javascript_.name()); \ | 375 TestBinaryMonotonicity(javascript_.name()); \ |
| 380 } | 376 } |
| 381 JSBINOP_LIST(TEST_FUNC) | 377 JSBINOP_LIST(TEST_FUNC) |
| 382 #undef TEST_FUNC | 378 #undef TEST_FUNC |
| 383 | 379 |
| 384 | 380 |
| 385 #define TEST_FUNC(name) \ | 381 #define TEST_FUNC(name) \ |
| 386 TEST_F(TyperTest, Monotonicity_##name) { \ | 382 TEST_F(TyperTest, Monotonicity_##name) { \ |
| 387 TestBinaryMonotonicity(javascript_.name(LanguageMode::SLOPPY)); \ | 383 TestBinaryMonotonicity(javascript_.name(Strength::WEAK)); \ |
| 388 TestBinaryMonotonicity(javascript_.name(LanguageMode::STRONG)); \ | 384 TestBinaryMonotonicity(javascript_.name(Strength::FIRM)); \ |
| 389 } | 385 } |
| 390 JSBINOP_WITH_STRONG_LIST(TEST_FUNC) | 386 JSBINOP_WITH_STRONG_LIST(TEST_FUNC) |
| 391 #undef TEST_FUNC | 387 #undef TEST_FUNC |
| 392 | 388 |
| 393 | 389 |
| 394 //------------------------------------------------------------------------------ | 390 //------------------------------------------------------------------------------ |
| 395 // Regression tests | 391 // Regression tests |
| 396 | 392 |
| 397 | 393 |
| 398 TEST_F(TyperTest, TypeRegressInt32Constant) { | 394 TEST_F(TyperTest, TypeRegressInt32Constant) { |
| 399 int values[] = {-5, 10}; | 395 int values[] = {-5, 10}; |
| 400 for (auto i : values) { | 396 for (auto i : values) { |
| 401 Node* c = graph()->NewNode(common()->Int32Constant(i)); | 397 Node* c = graph()->NewNode(common()->Int32Constant(i)); |
| 402 Type* type = NodeProperties::GetBounds(c).upper; | 398 Type* type = NodeProperties::GetBounds(c).upper; |
| 403 EXPECT_TRUE(type->Is(NewRange(i, i))); | 399 EXPECT_TRUE(type->Is(NewRange(i, i))); |
| 404 } | 400 } |
| 405 } | 401 } |
| OLD | NEW |