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

Unified Diff: Source/wtf/ArrayPiece.cpp

Issue 267133002: [webcrypto] Allow both ArrayBuffer and ArrayBufferView as inputs to crypto.subtle methods. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename ArrayBytes --> ArrayPiece Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/ArrayPiece.h ('k') | Source/wtf/Forward.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/ArrayPiece.cpp
diff --git a/Source/wtf/ArrayPiece.cpp b/Source/wtf/ArrayPiece.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f0cc5d42d241e8fcb85ac16ae48439413c06c23f
--- /dev/null
+++ b/Source/wtf/ArrayPiece.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/ArrayPiece.h"
+
+#include "wtf/ArrayBuffer.h"
+#include "wtf/ArrayBufferView.h"
+#include "wtf/Assertions.h"
+
+namespace WTF {
+
+ArrayPiece::ArrayPiece()
+{
+ initNull();
+}
+
+ArrayPiece::ArrayPiece(void* data, unsigned byteLength)
+{
+ initWithData(data, byteLength);
+}
+
+ArrayPiece::ArrayPiece(ArrayBuffer* buffer)
+{
+ if (buffer) {
+ initWithData(buffer->data(), buffer->byteLength());
+ } else {
+ initNull();
+ }
+}
+
+ArrayPiece::ArrayPiece(ArrayBufferView* buffer)
+{
+ if (buffer) {
+ initWithData(buffer->baseAddress(), buffer->byteLength());
+ } else {
+ initNull();
+ }
+}
+
+bool ArrayPiece::isNull() const
+{
+ return m_isNull;
+}
+
+void* ArrayPiece::data() const
+{
+ ASSERT(!isNull());
+ return m_data;
+}
+
+unsigned char* ArrayPiece::bytes() const
+{
+ return static_cast<unsigned char*>(data());
+}
+
+unsigned ArrayPiece::byteLength() const
+{
+ ASSERT(!isNull());
+ return m_byteLength;
+}
+
+void ArrayPiece::initWithData(void* data, unsigned byteLength)
+{
+ m_byteLength = byteLength;
+ m_data = data;
+ m_isNull = false;
+}
+
+void ArrayPiece::initNull()
+{
+ m_byteLength = 0;
+ m_data = 0;
+ m_isNull = true;
+}
+
+} // namespace WTF
« no previous file with comments | « Source/wtf/ArrayPiece.h ('k') | Source/wtf/Forward.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698