| Index: Source/wtf/ArrayBytes.cpp
|
| diff --git a/Source/wtf/ArrayBytes.cpp b/Source/wtf/ArrayBytes.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e99b1ac6b7108fa8a32d0ddaae7eb4b55957294b
|
| --- /dev/null
|
| +++ b/Source/wtf/ArrayBytes.cpp
|
| @@ -0,0 +1,78 @@
|
| +// Copyright 2014 The Chromium 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 "config.h"
|
| +#include "wtf/ArrayBytes.h"
|
| +
|
| +#include "wtf/ArrayBuffer.h"
|
| +#include "wtf/ArrayBufferView.h"
|
| +#include "wtf/Assertions.h"
|
| +
|
| +namespace WTF {
|
| +
|
| +ArrayBytes::ArrayBytes()
|
| +{
|
| + initNull();
|
| +}
|
| +
|
| +ArrayBytes::ArrayBytes(void* data, unsigned byteLength)
|
| +{
|
| + initWithData(data, byteLength);
|
| +}
|
| +
|
| +ArrayBytes::ArrayBytes(ArrayBuffer* buffer)
|
| +{
|
| + if (buffer) {
|
| + initWithData(buffer->data(), buffer->byteLength());
|
| + } else {
|
| + initNull();
|
| + }
|
| +}
|
| +
|
| +ArrayBytes::ArrayBytes(ArrayBufferView* buffer)
|
| +{
|
| + if (buffer) {
|
| + initWithData(buffer->baseAddress(), buffer->byteLength());
|
| + } else {
|
| + initNull();
|
| + }
|
| +}
|
| +
|
| +bool ArrayBytes::isNull() const
|
| +{
|
| + return m_isNull;
|
| +}
|
| +
|
| +void* ArrayBytes::data() const
|
| +{
|
| + ASSERT(!isNull());
|
| + return m_data;
|
| +}
|
| +
|
| +unsigned char* ArrayBytes::bytes() const
|
| +{
|
| + return static_cast<unsigned char*>(data());
|
| +}
|
| +
|
| +unsigned ArrayBytes::byteLength() const
|
| +{
|
| + ASSERT(!isNull());
|
| + return m_byteLength;
|
| +}
|
| +
|
| +void ArrayBytes::initWithData(void* data, unsigned byteLength)
|
| +{
|
| + m_byteLength = byteLength;
|
| + m_data = data;
|
| + m_isNull = false;
|
| +}
|
| +
|
| +void ArrayBytes::initNull()
|
| +{
|
| + m_byteLength = 0;
|
| + m_data = 0;
|
| + m_isNull = true;
|
| +}
|
| +
|
| +} // namespace WTF
|
|
|