| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/ast-expression-visitor.h" | 10 #include "src/ast-expression-visitor.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); | 44 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); |
| 45 | 45 |
| 46 ExpressionTypeCollector(&compilation_info, dst).Run(); | 46 ExpressionTypeCollector(&compilation_info, dst).Run(); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 TEST(VisitExpressions) { | 51 TEST(VisitExpressions) { |
| 52 v8::V8::Initialize(); | 52 v8::V8::Initialize(); |
| 53 HandleAndZoneScope handles; | 53 HandleAndZoneScope handles; |
| 54 ZoneVector<ExpressionTypeEntry> types(handles.main_zone()); | 54 Zone* zone = handles.main_zone(); |
| 55 ZoneVector<ExpressionTypeEntry> types(zone); |
| 55 const char test_function[] = | 56 const char test_function[] = |
| 56 "function GeometricMean(stdlib, foreign, buffer) {\n" | 57 "function GeometricMean(stdlib, foreign, buffer) {\n" |
| 57 " \"use asm\";\n" | 58 " \"use asm\";\n" |
| 58 "\n" | 59 "\n" |
| 59 " var exp = stdlib.Math.exp;\n" | 60 " var exp = stdlib.Math.exp;\n" |
| 60 " var log = stdlib.Math.log;\n" | 61 " var log = stdlib.Math.log;\n" |
| 61 " var values = new stdlib.Float64Array(buffer);\n" | 62 " var values = new stdlib.Float64Array(buffer);\n" |
| 62 "\n" | 63 "\n" |
| 63 " function logSum(start, end) {\n" | 64 " function logSum(start, end) {\n" |
| 64 " start = start|0;\n" | 65 " start = start|0;\n" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 267 } |
| 267 } | 268 } |
| 268 } | 269 } |
| 269 CHECK_TYPES_END | 270 CHECK_TYPES_END |
| 270 } | 271 } |
| 271 | 272 |
| 272 | 273 |
| 273 TEST(VisitEmptyForStatment) { | 274 TEST(VisitEmptyForStatment) { |
| 274 v8::V8::Initialize(); | 275 v8::V8::Initialize(); |
| 275 HandleAndZoneScope handles; | 276 HandleAndZoneScope handles; |
| 276 ZoneVector<ExpressionTypeEntry> types(handles.main_zone()); | 277 Zone* zone = handles.main_zone(); |
| 278 ZoneVector<ExpressionTypeEntry> types(zone); |
| 277 // Check that traversing an empty for statement works. | 279 // Check that traversing an empty for statement works. |
| 278 const char test_function[] = | 280 const char test_function[] = |
| 279 "function foo() {\n" | 281 "function foo() {\n" |
| 280 " for (;;) {}\n" | 282 " for (;;) {}\n" |
| 281 "}\n"; | 283 "}\n"; |
| 282 CollectTypes(&handles, test_function, &types); | 284 CollectTypes(&handles, test_function, &types); |
| 283 CHECK_TYPES_BEGIN { | 285 CHECK_TYPES_BEGIN { |
| 284 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {} | 286 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {} |
| 285 } | 287 } |
| 286 CHECK_TYPES_END | 288 CHECK_TYPES_END |
| 287 } | 289 } |
| 288 | 290 |
| 289 | 291 |
| 290 TEST(VisitSwitchStatment) { | 292 TEST(VisitSwitchStatment) { |
| 291 v8::V8::Initialize(); | 293 v8::V8::Initialize(); |
| 292 HandleAndZoneScope handles; | 294 HandleAndZoneScope handles; |
| 293 ZoneVector<ExpressionTypeEntry> types(handles.main_zone()); | 295 Zone* zone = handles.main_zone(); |
| 296 ZoneVector<ExpressionTypeEntry> types(zone); |
| 294 // Check that traversing a switch with a default works. | 297 // Check that traversing a switch with a default works. |
| 295 const char test_function[] = | 298 const char test_function[] = |
| 296 "function foo() {\n" | 299 "function foo() {\n" |
| 297 " switch (0) { case 1: break; default: break; }\n" | 300 " switch (0) { case 1: break; default: break; }\n" |
| 298 "}\n"; | 301 "}\n"; |
| 299 CollectTypes(&handles, test_function, &types); | 302 CollectTypes(&handles, test_function, &types); |
| 300 CHECK_TYPES_BEGIN { | 303 CHECK_TYPES_BEGIN { |
| 301 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { | 304 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { |
| 302 CHECK_EXPR(Assignment, DEFAULT_TYPE) { | 305 CHECK_EXPR(Assignment, DEFAULT_TYPE) { |
| 303 CHECK_VAR(.switch_tag, DEFAULT_TYPE); | 306 CHECK_VAR(.switch_tag, DEFAULT_TYPE); |
| 304 CHECK_EXPR(Literal, DEFAULT_TYPE); | 307 CHECK_EXPR(Literal, DEFAULT_TYPE); |
| 305 } | 308 } |
| 306 CHECK_EXPR(Literal, DEFAULT_TYPE); | 309 CHECK_EXPR(Literal, DEFAULT_TYPE); |
| 307 CHECK_VAR(.switch_tag, DEFAULT_TYPE); | 310 CHECK_VAR(.switch_tag, DEFAULT_TYPE); |
| 308 CHECK_EXPR(Literal, DEFAULT_TYPE); | 311 CHECK_EXPR(Literal, DEFAULT_TYPE); |
| 309 } | 312 } |
| 310 } | 313 } |
| 311 CHECK_TYPES_END | 314 CHECK_TYPES_END |
| 312 } | 315 } |
| 313 | 316 |
| 314 | 317 |
| 315 TEST(VisitThrow) { | 318 TEST(VisitThrow) { |
| 316 v8::V8::Initialize(); | 319 v8::V8::Initialize(); |
| 317 HandleAndZoneScope handles; | 320 HandleAndZoneScope handles; |
| 318 ZoneVector<ExpressionTypeEntry> types(handles.main_zone()); | 321 Zone* zone = handles.main_zone(); |
| 322 ZoneVector<ExpressionTypeEntry> types(zone); |
| 319 // Check that traversing an empty for statement works. | 323 // Check that traversing an empty for statement works. |
| 320 const char test_function[] = | 324 const char test_function[] = |
| 321 "function foo() {\n" | 325 "function foo() {\n" |
| 322 " throw 123;\n" | 326 " throw 123;\n" |
| 323 "}\n"; | 327 "}\n"; |
| 324 CollectTypes(&handles, test_function, &types); | 328 CollectTypes(&handles, test_function, &types); |
| 325 CHECK_TYPES_BEGIN { | 329 CHECK_TYPES_BEGIN { |
| 326 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { | 330 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { |
| 327 CHECK_EXPR(Throw, DEFAULT_TYPE) { CHECK_EXPR(Literal, DEFAULT_TYPE); } | 331 CHECK_EXPR(Throw, DEFAULT_TYPE) { CHECK_EXPR(Literal, DEFAULT_TYPE); } |
| 328 } | 332 } |
| 329 } | 333 } |
| 330 CHECK_TYPES_END | 334 CHECK_TYPES_END |
| 331 } | 335 } |
| 332 | 336 |
| 333 | 337 |
| 334 TEST(VisitYield) { | 338 TEST(VisitYield) { |
| 335 v8::V8::Initialize(); | 339 v8::V8::Initialize(); |
| 336 HandleAndZoneScope handles; | 340 HandleAndZoneScope handles; |
| 337 ZoneVector<ExpressionTypeEntry> types(handles.main_zone()); | 341 Zone* zone = handles.main_zone(); |
| 342 ZoneVector<ExpressionTypeEntry> types(zone); |
| 338 // Check that traversing an empty for statement works. | 343 // Check that traversing an empty for statement works. |
| 339 const char test_function[] = | 344 const char test_function[] = |
| 340 "function* foo() {\n" | 345 "function* foo() {\n" |
| 341 " yield 123;\n" | 346 " yield 123;\n" |
| 342 "}\n"; | 347 "}\n"; |
| 343 CollectTypes(&handles, test_function, &types); | 348 CollectTypes(&handles, test_function, &types); |
| 344 CHECK_TYPES_BEGIN { | 349 CHECK_TYPES_BEGIN { |
| 345 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { | 350 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { |
| 346 // Generator function yields generator on entry. | 351 // Generator function yields generator on entry. |
| 347 CHECK_EXPR(Yield, DEFAULT_TYPE) { | 352 CHECK_EXPR(Yield, DEFAULT_TYPE) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 358 } | 363 } |
| 359 // Then yields 123. | 364 // Then yields 123. |
| 360 CHECK_EXPR(Yield, DEFAULT_TYPE) { | 365 CHECK_EXPR(Yield, DEFAULT_TYPE) { |
| 361 CHECK_VAR(.generator_object, DEFAULT_TYPE); | 366 CHECK_VAR(.generator_object, DEFAULT_TYPE); |
| 362 CHECK_EXPR(Literal, DEFAULT_TYPE); | 367 CHECK_EXPR(Literal, DEFAULT_TYPE); |
| 363 } | 368 } |
| 364 } | 369 } |
| 365 } | 370 } |
| 366 CHECK_TYPES_END | 371 CHECK_TYPES_END |
| 367 } | 372 } |
| 373 |
| 374 |
| 375 TEST(VisitSkipping) { |
| 376 v8::V8::Initialize(); |
| 377 HandleAndZoneScope handles; |
| 378 Zone* zone = handles.main_zone(); |
| 379 ZoneVector<ExpressionTypeEntry> types(zone); |
| 380 // Check that traversing an empty for statement works. |
| 381 const char test_function[] = |
| 382 "function foo(x) {\n" |
| 383 " return (x + x) + 1;\n" |
| 384 "}\n"; |
| 385 CollectTypes(&handles, test_function, &types); |
| 386 CHECK_TYPES_BEGIN { |
| 387 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) { |
| 388 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) { |
| 389 // Skip x + x |
| 390 CHECK_SKIP(); |
| 391 CHECK_EXPR(Literal, DEFAULT_TYPE); |
| 392 } |
| 393 } |
| 394 } |
| 395 CHECK_TYPES_END |
| 396 } |
| OLD | NEW |