OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/DOMDataView.h" | 5 #include "core/dom/DOMDataView.h" |
6 | 6 |
7 #include "bindings/core/v8/DOMDataStore.h" | 7 #include "bindings/core/v8/DOMDataStore.h" |
8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
9 #include "platform/CheckedInt.h" | 9 #include "wtf/CheckedNumeric.h" |
10 #include "wtf/typed_arrays/ArrayBufferView.h" | 10 #include "wtf/typed_arrays/ArrayBufferView.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class DataView final : public ArrayBufferView { | 16 class DataView final : public ArrayBufferView { |
17 public: | 17 public: |
18 static PassRefPtr<DataView> create(ArrayBuffer* buffer, unsigned byteOffset,
unsigned byteLength) | 18 static PassRefPtr<DataView> create(ArrayBuffer* buffer, unsigned byteOffset,
unsigned byteLength) |
19 { | 19 { |
20 RELEASE_ASSERT(byteOffset <= buffer->byteLength()); | 20 CheckedNumeric<uint32_t> checkedMax = byteOffset; |
21 CheckedInt<uint32_t> checkedOffset(byteOffset); | 21 checkedMax += byteLength; |
22 CheckedInt<uint32_t> checkedLength(byteLength); | 22 RELEASE_ASSERT(checkedMax.ValueOrDie() <= buffer->byteLength()); |
23 CheckedInt<uint32_t> checkedMax = checkedOffset + checkedLength; | |
24 RELEASE_ASSERT(checkedMax.isValid()); | |
25 RELEASE_ASSERT(checkedMax.value() <= buffer->byteLength()); | |
26 return adoptRef(new DataView(buffer, byteOffset, byteLength)); | 23 return adoptRef(new DataView(buffer, byteOffset, byteLength)); |
27 } | 24 } |
28 | 25 |
29 unsigned byteLength() const override { return m_byteLength; } | 26 unsigned byteLength() const override { return m_byteLength; } |
30 ViewType type() const override { return TypeDataView; } | 27 ViewType type() const override { return TypeDataView; } |
31 unsigned typeSize() const override { return 1; } | 28 unsigned typeSize() const override { return 1; } |
32 | 29 |
33 protected: | 30 protected: |
34 void neuter() override | 31 void neuter() override |
35 { | 32 { |
(...skipping 26 matching lines...) Expand all Loading... |
62 if (v8Buffer.IsEmpty()) | 59 if (v8Buffer.IsEmpty()) |
63 return v8::Local<v8::Object>(); | 60 return v8::Local<v8::Object>(); |
64 DCHECK(v8Buffer->IsArrayBuffer()); | 61 DCHECK(v8Buffer->IsArrayBuffer()); |
65 | 62 |
66 v8::Local<v8::Object> wrapper = v8::DataView::New(v8Buffer.As<v8::ArrayBuffe
r>(), byteOffset(), byteLength()); | 63 v8::Local<v8::Object> wrapper = v8::DataView::New(v8Buffer.As<v8::ArrayBuffe
r>(), byteOffset(), byteLength()); |
67 | 64 |
68 return associateWithWrapper(isolate, wrapperTypeInfo, wrapper); | 65 return associateWithWrapper(isolate, wrapperTypeInfo, wrapper); |
69 } | 66 } |
70 | 67 |
71 } // namespace blink | 68 } // namespace blink |
OLD | NEW |