OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 "src/value-serializer.h" | 5 #include "src/value-serializer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "include/v8.h" | 10 #include "include/v8.h" |
(...skipping 2421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 | 2432 |
2433 private: | 2433 private: |
2434 static bool g_saved_flag; | 2434 static bool g_saved_flag; |
2435 }; | 2435 }; |
2436 | 2436 |
2437 bool ValueSerializerTestWithWasm::g_saved_flag = false; | 2437 bool ValueSerializerTestWithWasm::g_saved_flag = false; |
2438 | 2438 |
2439 // A simple module which exports an "increment" function. | 2439 // A simple module which exports an "increment" function. |
2440 // Copied from test/mjsunit/wasm/incrementer.wasm. | 2440 // Copied from test/mjsunit/wasm/incrementer.wasm. |
2441 const unsigned char kIncrementerWasm[] = { | 2441 const unsigned char kIncrementerWasm[] = { |
2442 0, 97, 115, 109, 13, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127, | 2442 0x00, 0x61, 0x73, 0x6d, 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, |
2443 3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110, | 2443 0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, |
2444 116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11, | 2444 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, |
2445 }; | 2445 0x08, 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a}; |
2446 | 2446 |
2447 TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) { | 2447 TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) { |
2448 RoundTripTest( | 2448 RoundTripTest( |
2449 [this]() { | 2449 [this]() { |
2450 return WasmCompiledModule::DeserializeOrCompile( | 2450 return WasmCompiledModule::DeserializeOrCompile( |
2451 isolate(), {nullptr, 0}, | 2451 isolate(), {nullptr, 0}, |
2452 {kIncrementerWasm, sizeof(kIncrementerWasm)}) | 2452 {kIncrementerWasm, sizeof(kIncrementerWasm)}) |
2453 .ToLocalChecked(); | 2453 .ToLocalChecked(); |
2454 }, | 2454 }, |
2455 [this](Local<Value> value) { | 2455 [this](Local<Value> value) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2514 0xff, 0x48, 0x83, 0xc4, 0x08, 0xeb, 0xb8, 0x66, 0x90, 0x02, 0x00, 0x00, | 2514 0xff, 0x48, 0x83, 0xc4, 0x08, 0xeb, 0xb8, 0x66, 0x90, 0x02, 0x00, 0x00, |
2515 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, | 2515 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, |
2516 0x0f, 0x39, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x00, | 2516 0x0f, 0x39, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x00, |
2517 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x20, 0x84, | 2517 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x20, 0x84, |
2518 0x0f, 0xcc, 0x6e, 0x7d, 0x01, 0x72, 0x98, 0x00, 0x0f, 0xdc, 0x6d, 0x0c, | 2518 0x0f, 0xcc, 0x6e, 0x7d, 0x01, 0x72, 0x98, 0x00, 0x0f, 0xdc, 0x6d, 0x0c, |
2519 0x0f, 0xb0, 0x84, 0x0d, 0x04, 0x84, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00, | 2519 0x0f, 0xb0, 0x84, 0x0d, 0x04, 0x84, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00, |
2520 0x00, 0x00, 0x00, 0x00, 0x84, 0xe0, 0x84, 0x84, 0x18, 0x2f, 0x2f, 0x2f, | 2520 0x00, 0x00, 0x00, 0x00, 0x84, 0xe0, 0x84, 0x84, 0x18, 0x2f, 0x2f, 0x2f, |
2521 0x2f, 0x2f}; | 2521 0x2f, 0x2f}; |
2522 | 2522 |
2523 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModule) { | 2523 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModule) { |
2524 if (true) return; // TODO(mtrofin): fix this test | |
2525 std::vector<uint8_t> raw( | 2524 std::vector<uint8_t> raw( |
2526 kSerializedIncrementerWasm, | 2525 kSerializedIncrementerWasm, |
2527 kSerializedIncrementerWasm + sizeof(kSerializedIncrementerWasm)); | 2526 kSerializedIncrementerWasm + sizeof(kSerializedIncrementerWasm)); |
2528 DecodeTest(raw, [this](Local<Value> value) { | 2527 DecodeTest(raw, [this](Local<Value> value) { |
2529 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); | 2528 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); |
2530 EXPECT_TRUE(EvaluateScriptForResultBool( | 2529 EXPECT_TRUE(EvaluateScriptForResultBool( |
2531 "new WebAssembly.Instance(result).exports.increment(8) === 9")); | 2530 "new WebAssembly.Instance(result).exports.increment(8) === 9")); |
2532 }); | 2531 }); |
2533 } | 2532 } |
2534 | 2533 |
2535 // As above, but with empty compiled data. Should work due to fallback to wire | 2534 // As above, but with empty compiled data. Should work due to fallback to wire |
2536 // data. | 2535 // data. |
2537 const unsigned char kSerializedIncrementerWasmWithInvalidCompiledData[] = { | 2536 const unsigned char kSerializedIncrementerWasmWithInvalidCompiledData[] = { |
2538 0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x2d, 0x00, 0x61, 0x73, 0x6d, | 2537 0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x2d, 0x00, 0x61, 0x73, 0x6d, |
2539 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, | 2538 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, |
2540 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 0x69, 0x6e, | 2539 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 0x69, 0x6e, |
2541 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 0x08, | 2540 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 0x08, |
2542 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x00}; | 2541 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x00}; |
2543 | 2542 |
2544 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidCompiledData) { | 2543 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidCompiledData) { |
2545 if (true) return; // TODO(titzer): regenerate this test | |
2546 std::vector<uint8_t> raw( | 2544 std::vector<uint8_t> raw( |
2547 kSerializedIncrementerWasmWithInvalidCompiledData, | 2545 kSerializedIncrementerWasmWithInvalidCompiledData, |
2548 kSerializedIncrementerWasmWithInvalidCompiledData + | 2546 kSerializedIncrementerWasmWithInvalidCompiledData + |
2549 sizeof(kSerializedIncrementerWasmWithInvalidCompiledData)); | 2547 sizeof(kSerializedIncrementerWasmWithInvalidCompiledData)); |
2550 DecodeTest(raw, [this](Local<Value> value) { | 2548 DecodeTest(raw, [this](Local<Value> value) { |
2551 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); | 2549 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); |
2552 EXPECT_TRUE(EvaluateScriptForResultBool( | 2550 EXPECT_TRUE(EvaluateScriptForResultBool( |
2553 "new WebAssembly.Instance(result).exports.increment(8) === 9")); | 2551 "new WebAssembly.Instance(result).exports.increment(8) === 9")); |
2554 }); | 2552 }); |
2555 } | 2553 } |
(...skipping 10 matching lines...) Expand all Loading... |
2566 InvalidDecodeTest(raw); | 2564 InvalidDecodeTest(raw); |
2567 } | 2565 } |
2568 | 2566 |
2569 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { | 2567 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { |
2570 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); | 2568 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); |
2571 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); | 2569 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); |
2572 } | 2570 } |
2573 | 2571 |
2574 } // namespace | 2572 } // namespace |
2575 } // namespace v8 | 2573 } // namespace v8 |
OLD | NEW |