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 "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/handles.h" | 7 #include "src/handles.h" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 ONE_EMPTY_FUNCTION, | 503 ONE_EMPTY_FUNCTION, |
504 // table declaration --------------------------------------------------- | 504 // table declaration --------------------------------------------------- |
505 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1}; | 505 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1}; |
506 | 506 |
507 ModuleResult result = DecodeModule(data, data + sizeof(data)); | 507 ModuleResult result = DecodeModule(data, data + sizeof(data)); |
508 EXPECT_OK(result); | 508 EXPECT_OK(result); |
509 if (result.ok()) { | 509 if (result.ok()) { |
510 EXPECT_EQ(1, result.val->signatures.size()); | 510 EXPECT_EQ(1, result.val->signatures.size()); |
511 EXPECT_EQ(1, result.val->functions.size()); | 511 EXPECT_EQ(1, result.val->functions.size()); |
512 EXPECT_EQ(1, result.val->function_tables.size()); | 512 EXPECT_EQ(1, result.val->function_tables.size()); |
513 EXPECT_EQ(1, result.val->function_tables[0].min_size); | 513 EXPECT_EQ(1, result.val->function_tables[0].values.size()); |
| 514 EXPECT_EQ(-1, result.val->function_tables[0].values[0]); |
514 } | 515 } |
515 if (result.val) delete result.val; | 516 if (result.val) delete result.val; |
516 } | 517 } |
517 | 518 |
518 TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) { | 519 TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) { |
519 static const byte data[] = { | 520 static const byte data[] = { |
520 // sig#0 --------------------------------------------------------------- | 521 // sig#0 --------------------------------------------------------------- |
521 SIGNATURES_SECTION_VOID_VOID, | 522 SIGNATURES_SECTION_VOID_VOID, |
522 // funcs --------------------------------------------------------------- | 523 // funcs --------------------------------------------------------------- |
523 ONE_EMPTY_FUNCTION, | 524 ONE_EMPTY_FUNCTION, |
524 // table declaration --------------------------------------------------- | 525 // table declaration --------------------------------------------------- |
525 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1, | 526 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1, |
526 // elements ------------------------------------------------------------ | 527 // elements ------------------------------------------------------------ |
527 SECTION(Element, 7), | 528 SECTION(Element, 7), |
528 1, // entry count | 529 1, // entry count |
529 TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0), | 530 TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0), |
530 1, // elements count | 531 1, // elements count |
531 FUNC_INDEX(0)}; | 532 FUNC_INDEX(0)}; |
532 | 533 |
533 ModuleResult result = DecodeModule(data, data + sizeof(data)); | 534 ModuleResult result = DecodeModule(data, data + sizeof(data)); |
534 EXPECT_OK(result); | 535 EXPECT_OK(result); |
535 if (result.ok()) { | 536 if (result.ok()) { |
536 EXPECT_EQ(1, result.val->signatures.size()); | 537 EXPECT_EQ(1, result.val->signatures.size()); |
537 EXPECT_EQ(1, result.val->functions.size()); | 538 EXPECT_EQ(1, result.val->functions.size()); |
538 EXPECT_EQ(1, result.val->function_tables.size()); | 539 EXPECT_EQ(1, result.val->function_tables.size()); |
539 EXPECT_EQ(1, result.val->function_tables[0].min_size); | 540 EXPECT_EQ(1, result.val->function_tables[0].values.size()); |
| 541 EXPECT_EQ(0, result.val->function_tables[0].values[0]); |
540 } | 542 } |
541 if (result.val) delete result.val; | 543 if (result.val) delete result.val; |
542 } | 544 } |
543 | 545 |
544 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { | 546 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
545 static const byte data[] = { | 547 static const byte data[] = { |
546 // sig#0 ------------------------------------------------------- | 548 // sig#0 ------------------------------------------------------- |
547 SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), | 549 SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), |
548 2, // -- | 550 2, // -- |
549 SIG_ENTRY_v_v, // void -> void | 551 SIG_ENTRY_v_v, // void -> void |
(...skipping 16 matching lines...) Expand all Loading... |
566 FUNC_INDEX(2), // -- | 568 FUNC_INDEX(2), // -- |
567 FUNC_INDEX(3), // -- | 569 FUNC_INDEX(3), // -- |
568 FOUR_EMPTY_BODIES}; | 570 FOUR_EMPTY_BODIES}; |
569 | 571 |
570 ModuleResult result = DecodeModule(data, data + sizeof(data)); | 572 ModuleResult result = DecodeModule(data, data + sizeof(data)); |
571 EXPECT_OK(result); | 573 EXPECT_OK(result); |
572 if (result.ok()) { | 574 if (result.ok()) { |
573 EXPECT_EQ(2, result.val->signatures.size()); | 575 EXPECT_EQ(2, result.val->signatures.size()); |
574 EXPECT_EQ(4, result.val->functions.size()); | 576 EXPECT_EQ(4, result.val->functions.size()); |
575 EXPECT_EQ(1, result.val->function_tables.size()); | 577 EXPECT_EQ(1, result.val->function_tables.size()); |
576 EXPECT_EQ(8, result.val->function_tables[0].min_size); | 578 EXPECT_EQ(8, result.val->function_tables[0].values.size()); |
| 579 for (int i = 0; i < 8; i++) { |
| 580 EXPECT_EQ(i & 3, result.val->function_tables[0].values[i]); |
| 581 } |
577 } | 582 } |
578 if (result.val) delete result.val; | 583 if (result.val) delete result.val; |
579 } | 584 } |
580 | 585 |
581 TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) { | 586 TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) { |
582 static const byte data[] = { | 587 static const byte data[] = { |
583 // sig#0 ------------------------------------------------------- | 588 // sig#0 ------------------------------------------------------- |
584 SIGNATURES_SECTION_VOID_VOID, | 589 SIGNATURES_SECTION_VOID_VOID, |
585 // indirect table ---------------------------------------------- | 590 // indirect table ---------------------------------------------- |
586 SECTION(Table, 4), ENTRY_COUNT(1), 1, 0, 0, | 591 SECTION(Table, 4), ENTRY_COUNT(1), 1, 0, 0, |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- | 1292 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- |
1288 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- | 1293 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- |
1289 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- | 1294 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- |
1290 }; | 1295 }; |
1291 EXPECT_VERIFIES(data); | 1296 EXPECT_VERIFIES(data); |
1292 } | 1297 } |
1293 | 1298 |
1294 } // namespace wasm | 1299 } // namespace wasm |
1295 } // namespace internal | 1300 } // namespace internal |
1296 } // namespace v8 | 1301 } // namespace v8 |
OLD | NEW |