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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 }); | 47 }); |
48 for (Local<Context> context : | 48 for (Local<Context> context : |
49 {serialization_context_, deserialization_context_}) { | 49 {serialization_context_, deserialization_context_}) { |
50 context->Global() | 50 context->Global() |
51 ->CreateDataProperty( | 51 ->CreateDataProperty( |
52 context, StringFromUtf8("ExampleHostObject"), | 52 context, StringFromUtf8("ExampleHostObject"), |
53 function_template->GetFunction(context).ToLocalChecked()) | 53 function_template->GetFunction(context).ToLocalChecked()) |
54 .ToChecked(); | 54 .ToChecked(); |
55 } | 55 } |
56 host_object_constructor_template_ = function_template; | 56 host_object_constructor_template_ = function_template; |
| 57 isolate_ = reinterpret_cast<i::Isolate*>(isolate()); |
| 58 } |
| 59 |
| 60 ~ValueSerializerTest() { |
| 61 // In some cases unhandled scheduled exceptions from current test produce |
| 62 // that Context::New(isolate()) from next test's constructor returns NULL. |
| 63 // In order to prevent that, we added destructor which will clear scheduled |
| 64 // exceptions just for the current test from test case. |
| 65 if (isolate_->has_scheduled_exception()) { |
| 66 isolate_->clear_scheduled_exception(); |
| 67 } |
57 } | 68 } |
58 | 69 |
59 const Local<Context>& serialization_context() { | 70 const Local<Context>& serialization_context() { |
60 return serialization_context_; | 71 return serialization_context_; |
61 } | 72 } |
62 const Local<Context>& deserialization_context() { | 73 const Local<Context>& deserialization_context() { |
63 return deserialization_context_; | 74 return deserialization_context_; |
64 } | 75 } |
65 | 76 |
66 // Overridden in more specific fixtures. | 77 // Overridden in more specific fixtures. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 return host_object_constructor_template_->GetFunction(context) | 260 return host_object_constructor_template_->GetFunction(context) |
250 .ToLocalChecked() | 261 .ToLocalChecked() |
251 ->NewInstance(context, argc, argv) | 262 ->NewInstance(context, argc, argv) |
252 .ToLocalChecked(); | 263 .ToLocalChecked(); |
253 } | 264 } |
254 | 265 |
255 private: | 266 private: |
256 Local<Context> serialization_context_; | 267 Local<Context> serialization_context_; |
257 Local<Context> deserialization_context_; | 268 Local<Context> deserialization_context_; |
258 Local<FunctionTemplate> host_object_constructor_template_; | 269 Local<FunctionTemplate> host_object_constructor_template_; |
| 270 i::Isolate* isolate_; |
259 | 271 |
260 DISALLOW_COPY_AND_ASSIGN(ValueSerializerTest); | 272 DISALLOW_COPY_AND_ASSIGN(ValueSerializerTest); |
261 }; | 273 }; |
262 | 274 |
263 TEST_F(ValueSerializerTest, DecodeInvalid) { | 275 TEST_F(ValueSerializerTest, DecodeInvalid) { |
264 // Version tag but no content. | 276 // Version tag but no content. |
265 InvalidDecodeTest({0xff}); | 277 InvalidDecodeTest({0xff}); |
266 // Version too large. | 278 // Version too large. |
267 InvalidDecodeTest({0xff, 0x7f, 0x5f}); | 279 InvalidDecodeTest({0xff, 0x7f, 0x5f}); |
268 // Nonsense tag. | 280 // Nonsense tag. |
(...skipping 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2566 InvalidDecodeTest(raw); | 2578 InvalidDecodeTest(raw); |
2567 } | 2579 } |
2568 | 2580 |
2569 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { | 2581 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { |
2570 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); | 2582 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); |
2571 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); | 2583 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); |
2572 } | 2584 } |
2573 | 2585 |
2574 } // namespace | 2586 } // namespace |
2575 } // namespace v8 | 2587 } // namespace v8 |
OLD | NEW |