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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/ArrayPiece.h ('k') | Source/wtf/Forward.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "wtf/ArrayPiece.h"
7
8 #include "wtf/ArrayBuffer.h"
9 #include "wtf/ArrayBufferView.h"
10 #include "wtf/Assertions.h"
11
12 namespace WTF {
13
14 ArrayPiece::ArrayPiece()
15 {
16 initNull();
17 }
18
19 ArrayPiece::ArrayPiece(void* data, unsigned byteLength)
20 {
21 initWithData(data, byteLength);
22 }
23
24 ArrayPiece::ArrayPiece(ArrayBuffer* buffer)
25 {
26 if (buffer) {
27 initWithData(buffer->data(), buffer->byteLength());
28 } else {
29 initNull();
30 }
31 }
32
33 ArrayPiece::ArrayPiece(ArrayBufferView* buffer)
34 {
35 if (buffer) {
36 initWithData(buffer->baseAddress(), buffer->byteLength());
37 } else {
38 initNull();
39 }
40 }
41
42 bool ArrayPiece::isNull() const
43 {
44 return m_isNull;
45 }
46
47 void* ArrayPiece::data() const
48 {
49 ASSERT(!isNull());
50 return m_data;
51 }
52
53 unsigned char* ArrayPiece::bytes() const
54 {
55 return static_cast<unsigned char*>(data());
56 }
57
58 unsigned ArrayPiece::byteLength() const
59 {
60 ASSERT(!isNull());
61 return m_byteLength;
62 }
63
64 void ArrayPiece::initWithData(void* data, unsigned byteLength)
65 {
66 m_byteLength = byteLength;
67 m_data = data;
68 m_isNull = false;
69 }
70
71 void ArrayPiece::initNull()
72 {
73 m_byteLength = 0;
74 m_data = 0;
75 m_isNull = true;
76 }
77
78 } // namespace WTF
OLDNEW
« 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