chromium/v8/test/unittests/objects/value-serializer-unittest.cc

// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/objects/value-serializer.h"

#include <algorithm>
#include <string>

#include "include/v8-context.h"
#include "include/v8-date.h"
#include "include/v8-function.h"
#include "include/v8-json.h"
#include "include/v8-local-handle.h"
#include "include/v8-primitive-object.h"
#include "include/v8-template.h"
#include "include/v8-value-serializer-version.h"
#include "include/v8-value-serializer.h"
#include "include/v8-wasm.h"
#include "src/api/api-inl.h"
#include "src/base/build_config.h"
#include "src/objects/backing-store.h"
#include "src/objects/js-array-buffer-inl.h"
#include "src/objects/js-array-buffer.h"
#include "src/objects/objects-inl.h"
#include "test/common/flag-utils.h"
#include "test/unittests/heap/heap-utils.h"
#include "test/unittests/test-utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
#endif  // V8_ENABLE_WEBASSEMBLY

namespace v8 {
namespace {

_;
Invoke;
Return;

class ValueSerializerTest : public TestWithIsolate {};

TEST_F(ValueSerializerTest, DecodeInvalid) {}

TEST_F(ValueSerializerTest, RoundTripOddball) {}

TEST_F(ValueSerializerTest, DecodeOddball) {}

TEST_F(ValueSerializerTest, EncodeArrayStackOverflow) {}

TEST_F(ValueSerializerTest, EncodeObjectStackOverflow) {}

TEST_F(ValueSerializerTest, DecodeArrayStackOverflow) {}

TEST_F(ValueSerializerTest, DecodeObjectStackOverflow) {}

TEST_F(ValueSerializerTest, DecodeVerifyObjectCount) {}

TEST_F(ValueSerializerTest, RoundTripNumber) {}

TEST_F(ValueSerializerTest, DecodeNumber) {}

TEST_F(ValueSerializerTest, RoundTripBigInt) {}

TEST_F(ValueSerializerTest, DecodeBigInt) {}

// String constants (in UTF-8) used for string encoding tests.
static const char kHelloString[] =;
static const char kQuebecString[] =;
static const char kEmojiString[] =;

TEST_F(ValueSerializerTest, RoundTripString) {}

TEST_F(ValueSerializerTest, DecodeString) {}

TEST_F(ValueSerializerTest, DecodeInvalidString) {}

TEST_F(ValueSerializerTest, EncodeTwoByteStringUsesPadding) {}

TEST_F(ValueSerializerTest, RoundTripDictionaryObject) {}

TEST_F(ValueSerializerTest, DecodeDictionaryObject) {}

TEST_F(ValueSerializerTest, InvalidDecodeObjectWithInvalidKeyType) {}

TEST_F(ValueSerializerTest, RoundTripOnlyOwnEnumerableStringKeys) {}

TEST_F(ValueSerializerTest, RoundTripTrickyGetters) {}

TEST_F(ValueSerializerTest, RoundTripDictionaryObjectForTransitions) {}

TEST_F(ValueSerializerTest, DecodeDictionaryObjectVersion0) {}

TEST_F(ValueSerializerTest, RoundTripArray) {}

TEST_F(ValueSerializerTest, DecodeArray) {}

TEST_F(ValueSerializerTest, DecodeInvalidOverLargeArray) {}

TEST_F(ValueSerializerTest, RoundTripArrayWithNonEnumerableElement) {}

TEST_F(ValueSerializerTest, RoundTripArrayWithTrickyGetters) {}

TEST_F(ValueSerializerTest, DecodeSparseArrayVersion0) {}

TEST_F(ValueSerializerTest, RoundTripDenseArrayContainingUndefined) {}

TEST_F(ValueSerializerTest,
       DecodeDenseArrayContainingUndefinedBackwardCompatibility) {}

TEST_F(ValueSerializerTest, DecodeDenseArrayContainingUndefined) {}

TEST_F(ValueSerializerTest, RoundTripDate) {}

TEST_F(ValueSerializerTest, DecodeDate) {}

TEST_F(ValueSerializerTest, RoundTripValueObjects) {}

TEST_F(ValueSerializerTest, RejectsOtherValueObjects) {}

TEST_F(ValueSerializerTest, DecodeValueObjects) {}

TEST_F(ValueSerializerTest, RoundTripRegExp) {}

TEST_F(ValueSerializerTest, DecodeRegExp) {}

// Tests that invalid flags are not accepted by the deserializer.
TEST_F(ValueSerializerTest, DecodeRegExpDotAll) {}

TEST_F(ValueSerializerTest, DecodeLinearRegExp) {}

TEST_F(ValueSerializerTest, DecodeHasIndicesRegExp) {}

TEST_F(ValueSerializerTest, DecodeRegExpUnicodeSets) {}

TEST_F(ValueSerializerTest, RoundTripMap) {}

TEST_F(ValueSerializerTest, DecodeMap) {}

TEST_F(ValueSerializerTest, RoundTripMapWithTrickyGetters) {}

TEST_F(ValueSerializerTest, RoundTripSet) {}

TEST_F(ValueSerializerTest, DecodeSet) {}

TEST_F(ValueSerializerTest, RoundTripSetWithTrickyGetters) {}

TEST_F(ValueSerializerTest, RoundTripArrayBuffer) {}

TEST_F(ValueSerializerTest, RoundTripResizableArrayBuffer) {}

TEST_F(ValueSerializerTest, DecodeArrayBuffer) {}

TEST_F(ValueSerializerTest, DecodeInvalidArrayBuffer) {}

TEST_F(ValueSerializerTest, DecodeInvalidResizableArrayBuffer) {}

// An array buffer allocator that never has available memory.
class OOMArrayBufferAllocator : public ArrayBuffer::Allocator {};

TEST_F(ValueSerializerTest, DecodeArrayBufferOOM) {}

// Includes an ArrayBuffer wrapper marked for transfer from the serialization
// context to the deserialization context.
class ValueSerializerTestWithArrayBufferTransfer : public ValueSerializerTest {};

TEST_F(ValueSerializerTestWithArrayBufferTransfer,
       RoundTripArrayBufferTransfer) {}

TEST_F(ValueSerializerTest, RoundTripTypedArray) {}

TEST_F(ValueSerializerTest, RoundTripRabBackedLengthTrackingTypedArray) {}

TEST_F(ValueSerializerTest, RoundTripRabBackedNonLengthTrackingTypedArray) {}

TEST_F(ValueSerializerTest, DecodeTypedArray) {}

TEST_F(ValueSerializerTest, DecodeTypedArrayBackwardsCompatiblity) {}

TEST_F(ValueSerializerTest, DecodeTypedArrayBrokenData) {}

TEST_F(ValueSerializerTest, DecodeInvalidTypedArray) {}

TEST_F(ValueSerializerTest, RoundTripDataView) {}

TEST_F(ValueSerializerTest, DecodeDataView) {}

TEST_F(ValueSerializerTest, RoundTripRabBackedDataView) {}

TEST_F(ValueSerializerTest, RoundTripRabBackedLengthTrackingDataView) {}

TEST_F(ValueSerializerTest, DecodeDataViewBackwardsCompatibility) {}

TEST_F(ValueSerializerTest, DecodeArrayWithLengthProperty1) {}

TEST_F(ValueSerializerTest, DecodeArrayWithLengthProperty2) {}

TEST_F(ValueSerializerTest, DecodeInvalidDataView) {}

class ValueSerializerTestWithSharedArrayBufferClone
    : public ValueSerializerTest {};

TEST_F(ValueSerializerTestWithSharedArrayBufferClone,
       RoundTripSharedArrayBufferClone) {}

#if V8_ENABLE_WEBASSEMBLY
TEST_F(ValueSerializerTestWithSharedArrayBufferClone,
       RoundTripWebAssemblyMemory) {}

TEST_F(ValueSerializerTestWithSharedArrayBufferClone,
       RoundTripWebAssemblyMemory_WithPreviousReference) {}
#endif  // V8_ENABLE_WEBASSEMBLY

TEST_F(ValueSerializerTest, UnsupportedHostObject) {}

class ValueSerializerTestWithHostObject : public ValueSerializerTest {};

// This is a tag that is used in V8. Using this ensures that we have separate
// tag namespaces.
const uint8_t ValueSerializerTestWithHostObject::kExampleHostObjectTag =;

TEST_F(ValueSerializerTestWithHostObject, RoundTripUint32) {}

TEST_F(ValueSerializerTestWithHostObject, RoundTripUint64) {}

TEST_F(ValueSerializerTestWithHostObject, RoundTripDouble) {}

TEST_F(ValueSerializerTestWithHostObject, RoundTripRawBytes) {}

TEST_F(ValueSerializerTestWithHostObject, RoundTripSameObject) {}

TEST_F(ValueSerializerTestWithHostObject, DecodeSimpleHostObject) {}

TEST_F(ValueSerializerTestWithHostObject,
       RoundTripHostJSObjectWithoutCustomHostObject) {}

TEST_F(ValueSerializerTestWithHostObject, RoundTripHostJSObject) {}

class ValueSerializerTestWithHostArrayBufferView
    : public ValueSerializerTestWithHostObject {};

TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) {}

#if V8_ENABLE_WEBASSEMBLY
// It's expected that WebAssembly has more exhaustive tests elsewhere; this
// mostly checks that the logic to embed it in structured clone serialization
// works correctly.

// A simple module which exports an "increment" function.
// Copied from test/mjsunit/wasm/incrementer.wasm.
constexpr uint8_t kIncrementerWasm[] =;

class ValueSerializerTestWithWasm : public ValueSerializerTest {};

bool ValueSerializerTestWithWasm::g_saved_flag =;
const char* ValueSerializerTestWithWasm::kUnsupportedSerialization =;

// The default implementation of the serialization
// delegate throws when trying to serialize wasm. The
// embedder must decide serialization policy.
TEST_F(ValueSerializerTestWithWasm, DefaultSerializationDelegate) {}

// The default deserializer throws if wasm transfer is attempted
TEST_F(ValueSerializerTestWithWasm, DefaultDeserializationDelegate) {}

// We only want to allow deserialization through
// transferred modules - which requres both serializer
// and deserializer to understand that - or through
// explicitly allowing inlined data, which requires
// deserializer opt-in (we default the serializer to
// inlined data because we don't trust that data on the
// receiving end anyway).

TEST_F(ValueSerializerTestWithWasm, RoundtripWasmTransfer) {}

TEST_F(ValueSerializerTestWithWasm, CannotTransferWasmWhenExpectingInline) {}

TEST_F(ValueSerializerTestWithWasm, ComplexObjectDuplicateTransfer) {}

TEST_F(ValueSerializerTestWithWasm, ComplexObjectWithManyTransfer) {}
#endif  // V8_ENABLE_WEBASSEMBLY

class ValueSerializerTestWithLimitedMemory : public ValueSerializerTest {};

TEST_F(ValueSerializerTestWithLimitedMemory, FailIfNoMemoryInWriteHostObject) {}

// We only have basic tests and tests for .stack here, because we have more
// comprehensive tests as web platform tests.
TEST_F(ValueSerializerTest, RoundTripError) {}

TEST_F(ValueSerializerTest, DefaultErrorStack) {}

TEST_F(ValueSerializerTest, ModifiedErrorStack) {}

TEST_F(ValueSerializerTest, NonStringErrorStack) {}

TEST_F(ValueSerializerTest, InvalidLegacyFormatData) {}

}  // namespace
}  // namespace v8