Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: test/unittests/wasm/module-decoder-unittest.cc

Issue 2493433002: [wasm] Only immutable imported globals are valid initializer expressions (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/wasm/module-decoder.cc ('K') | « src/wasm/module-decoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 EXPECT_EQ(0, result.val->signatures[0]->parameter_count()); 411 EXPECT_EQ(0, result.val->signatures[0]->parameter_count());
412 EXPECT_EQ(1, result.val->signatures[1]->parameter_count()); 412 EXPECT_EQ(1, result.val->signatures[1]->parameter_count());
413 EXPECT_EQ(2, result.val->signatures[2]->parameter_count()); 413 EXPECT_EQ(2, result.val->signatures[2]->parameter_count());
414 } 414 }
415 if (result.val) delete result.val; 415 if (result.val) delete result.val;
416 416
417 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 417 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
418 } 418 }
419 419
420 TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
421 const byte data[] = {
422 SECTION(Import, 8), // section header
423 1, // number of imports
424 NAME_LENGTH(1), // --
425 'm', // module name
426 NAME_LENGTH(1), // --
427 'f', // global name
428 kExternalGlobal, // import kind
429 kLocalI32, // type
430 0, // mutability
431 SECTION(Memory, 4),
432 ENTRY_COUNT(1),
433 kResizableMaximumFlag,
434 28,
435 28,
436 SECTION(Data, 9),
437 ENTRY_COUNT(1),
438 LINEAR_MEMORY_INDEX_0,
439 WASM_INIT_EXPR_GLOBAL(0), // dest addr
440 U32V_1(3), // source size
441 'a',
442 'b',
443 'c' // data bytes
444 };
445 EXPECT_VERIFIES(data);
446 }
447 TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
448 // Only an immutable imported global can be used as an init_expr.
449 const byte data[] = {
450 SECTION(Import, 8), // section header
451 1, // number of imports
452 NAME_LENGTH(1), // --
453 'm', // module name
454 NAME_LENGTH(1), // --
455 'f', // global name
456 kExternalGlobal, // import kind
457 kLocalI32, // type
458 1, // mutability
459 SECTION(Memory, 4),
460 ENTRY_COUNT(1),
461 kResizableMaximumFlag,
462 28,
463 28,
464 SECTION(Data, 9),
465 ENTRY_COUNT(1),
466 LINEAR_MEMORY_INDEX_0,
467 WASM_INIT_EXPR_GLOBAL(0), // dest addr
468 U32V_1(3), // source size
469 'a',
470 'b',
471 'c' // data bytes
472 };
473 EXPECT_FAILURE(data);
474 }
475 TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableGlobal) {
476 // Only an immutable imported global can be used as an init_expr.
477 const byte data[] = {
478 SECTION(Memory, 4),
479 ENTRY_COUNT(1),
480 kResizableMaximumFlag,
481 28,
482 28,
483 SECTION(Global, 8), // --
484 1,
485 kLocalI32, // local type
486 0, // immutable
487 WASM_INIT_EXPR_I32V_3(0x9bbaa), // init
488 SECTION(Data, 9),
489 ENTRY_COUNT(1),
490 LINEAR_MEMORY_INDEX_0,
491 WASM_INIT_EXPR_GLOBAL(0), // dest addr
492 U32V_1(3), // source size
493 'a',
494 'b',
495 'c' // data bytes
496 };
497 EXPECT_FAILURE(data);
498 }
499
420 TEST_F(WasmModuleVerifyTest, OneDataSegment) { 500 TEST_F(WasmModuleVerifyTest, OneDataSegment) {
421 const byte kDataSegmentSourceOffset = 24; 501 const byte kDataSegmentSourceOffset = 24;
422 const byte data[] = { 502 const byte data[] = {
423 SECTION(Memory, 4), 503 SECTION(Memory, 4),
424 ENTRY_COUNT(1), 504 ENTRY_COUNT(1),
425 kResizableMaximumFlag, 505 kResizableMaximumFlag,
426 28, 506 28,
427 28, 507 28,
428 SECTION(Data, 11), 508 SECTION(Data, 11),
429 ENTRY_COUNT(1), 509 ENTRY_COUNT(1),
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- 1470 SECTION(Unknown, 4), 1, 'X', 17, 18, // --
1391 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- 1471 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
1392 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- 1472 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
1393 }; 1473 };
1394 EXPECT_VERIFIES(data); 1474 EXPECT_VERIFIES(data);
1395 } 1475 }
1396 1476
1397 } // namespace wasm 1477 } // namespace wasm
1398 } // namespace internal 1478 } // namespace internal
1399 } // namespace v8 1479 } // namespace v8
OLDNEW
« src/wasm/module-decoder.cc ('K') | « src/wasm/module-decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698