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

Side by Side Diff: Source/wtf/ArrayBytes.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: Remove buffer check 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
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/ArrayBytes.h"
7
8 #include "wtf/ArrayBuffer.h"
9 #include "wtf/ArrayBufferView.h"
10 #include "wtf/Assertions.h"
11
12 namespace WTF {
13
14 ArrayBytes::ArrayBytes()
15 {
16 initNull();
17 }
18
19 ArrayBytes::ArrayBytes(void* data, unsigned byteLength)
20 {
21 initWithData(data, byteLength);
22 }
23
24 ArrayBytes::ArrayBytes(ArrayBuffer* buffer)
25 {
26 if (buffer) {
27 initWithData(buffer->data(), buffer->byteLength());
28 } else {
29 initNull();
30 }
31 }
32
33 ArrayBytes::ArrayBytes(ArrayBufferView* buffer)
34 {
35 if (buffer) {
36 initWithData(buffer->baseAddress(), buffer->byteLength());
37 } else {
38 initNull();
39 }
40 }
41
42 bool ArrayBytes::isNull() const
43 {
44 return m_isNull;
45 }
46
47 void* ArrayBytes::data() const
48 {
49 ASSERT(!isNull());
50 return m_data;
51 }
52
53 unsigned char* ArrayBytes::bytes() const
54 {
55 return static_cast<unsigned char*>(data());
56 }
57
58 unsigned ArrayBytes::byteLength() const
59 {
60 ASSERT(!isNull());
61 return m_byteLength;
62 }
63
64 void ArrayBytes::initWithData(void* data, unsigned byteLength)
65 {
66 m_byteLength = byteLength;
67 m_data = data;
68 m_isNull = false;
69 }
70
71 void ArrayBytes::initNull()
72 {
73 m_byteLength = 0;
74 m_data = 0;
75 m_isNull = true;
76 }
77
78 } // namespace WTF
OLDNEW
« Source/wtf/ArrayBytes.h ('K') | « Source/wtf/ArrayBytes.h ('k') | Source/wtf/Forward.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698