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

Side by Side Diff: test/unittests/value-serializer-unittest.cc

Issue 2709023003: ValueSerializer: Add an explicit tag for host objects. (Closed)
Patch Set: correct version number Created 3 years, 10 months 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
« no previous file with comments | « src/value-serializer.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 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 2352 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 2363
2364 SerializerDelegate serializer_delegate_; 2364 SerializerDelegate serializer_delegate_;
2365 DeserializerDelegate deserializer_delegate_; 2365 DeserializerDelegate deserializer_delegate_;
2366 ValueSerializer* serializer_; 2366 ValueSerializer* serializer_;
2367 ValueDeserializer* deserializer_; 2367 ValueDeserializer* deserializer_;
2368 2368
2369 friend class SerializerDelegate; 2369 friend class SerializerDelegate;
2370 friend class DeserializerDelegate; 2370 friend class DeserializerDelegate;
2371 }; 2371 };
2372 2372
2373 // This is a tag that's not used in V8. 2373 // This is a tag that is used in V8. Using this ensures that we have separate
2374 const uint8_t ValueSerializerTestWithHostObject::kExampleHostObjectTag = '+'; 2374 // tag namespaces.
2375 const uint8_t ValueSerializerTestWithHostObject::kExampleHostObjectTag = 'T';
2375 2376
2376 TEST_F(ValueSerializerTestWithHostObject, RoundTripUint32) { 2377 TEST_F(ValueSerializerTestWithHostObject, RoundTripUint32) {
2377 // The host can serialize data as uint32_t. 2378 // The host can serialize data as uint32_t.
2378 EXPECT_CALL(serializer_delegate_, WriteHostObject(isolate(), _)) 2379 EXPECT_CALL(serializer_delegate_, WriteHostObject(isolate(), _))
2379 .WillRepeatedly(Invoke([this](Isolate*, Local<Object> object) { 2380 .WillRepeatedly(Invoke([this](Isolate*, Local<Object> object) {
2380 uint32_t value = 0; 2381 uint32_t value = 0;
2381 EXPECT_TRUE(object->GetInternalField(0) 2382 EXPECT_TRUE(object->GetInternalField(0)
2382 ->Uint32Value(serialization_context()) 2383 ->Uint32Value(serialization_context())
2383 .To(&value)); 2384 .To(&value));
2384 WriteExampleHostObjectTag(); 2385 WriteExampleHostObjectTag();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2537 })); 2538 }));
2538 RoundTripTest( 2539 RoundTripTest(
2539 "({ a: new ExampleHostObject(), get b() { return this.a; }})", 2540 "({ a: new ExampleHostObject(), get b() { return this.a; }})",
2540 [this](Local<Value> value) { 2541 [this](Local<Value> value) {
2541 EXPECT_TRUE(EvaluateScriptForResultBool( 2542 EXPECT_TRUE(EvaluateScriptForResultBool(
2542 "result.a instanceof ExampleHostObject")); 2543 "result.a instanceof ExampleHostObject"));
2543 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 2544 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
2544 }); 2545 });
2545 } 2546 }
2546 2547
2548 TEST_F(ValueSerializerTestWithHostObject, DecodeSimpleHostObject) {
2549 EXPECT_CALL(deserializer_delegate_, ReadHostObject(isolate()))
2550 .WillRepeatedly(Invoke([this](Isolate*) {
2551 EXPECT_TRUE(ReadExampleHostObjectTag());
2552 return NewHostObject(deserialization_context(), 0, nullptr);
2553 }));
2554 DecodeTest(
2555 {0xff, 0x0d, 0x5c, kExampleHostObjectTag}, [this](Local<Value> value) {
2556 EXPECT_TRUE(EvaluateScriptForResultBool(
2557 "Object.getPrototypeOf(result) === ExampleHostObject.prototype"));
2558 });
2559 }
2560
2547 class ValueSerializerTestWithHostArrayBufferView 2561 class ValueSerializerTestWithHostArrayBufferView
2548 : public ValueSerializerTestWithHostObject { 2562 : public ValueSerializerTestWithHostObject {
2549 protected: 2563 protected:
2550 void BeforeEncode(ValueSerializer* serializer) override { 2564 void BeforeEncode(ValueSerializer* serializer) override {
2551 ValueSerializerTestWithHostObject::BeforeEncode(serializer); 2565 ValueSerializerTestWithHostObject::BeforeEncode(serializer);
2552 serializer_->SetTreatArrayBufferViewsAsHostObjects(true); 2566 serializer_->SetTreatArrayBufferViewsAsHostObjects(true);
2553 } 2567 }
2554 }; 2568 };
2555 2569
2556 TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) { 2570 TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 InvalidDecodeTest(raw); 2744 InvalidDecodeTest(raw);
2731 } 2745 }
2732 2746
2733 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { 2747 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) {
2734 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); 2748 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00});
2735 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); 2749 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f});
2736 } 2750 }
2737 2751
2738 } // namespace 2752 } // namespace
2739 } // namespace v8 2753 } // namespace v8
OLDNEW
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698