| 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 "wtf/CheckedNumeric.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, | 18 static PassRefPtr<DataView> create(ArrayBuffer* buffer, |
| 19 unsigned byteOffset, | 19 unsigned byteOffset, |
| 20 unsigned byteLength) { | 20 unsigned byteLength) { |
| 21 CheckedNumeric<uint32_t> checkedMax = byteOffset; | 21 CheckedNumeric<uint32_t> checkedMax = byteOffset; |
| 22 checkedMax += byteLength; | 22 checkedMax += byteLength; |
| 23 RELEASE_ASSERT(checkedMax.ValueOrDie() <= buffer->byteLength()); | 23 CHECK_LE(checkedMax.ValueOrDie(), buffer->byteLength()); |
| 24 return adoptRef(new DataView(buffer, byteOffset, byteLength)); | 24 return adoptRef(new DataView(buffer, byteOffset, byteLength)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 unsigned byteLength() const override { return m_byteLength; } | 27 unsigned byteLength() const override { return m_byteLength; } |
| 28 ViewType type() const override { return TypeDataView; } | 28 ViewType type() const override { return TypeDataView; } |
| 29 unsigned typeSize() const override { return 1; } | 29 unsigned typeSize() const override { return 1; } |
| 30 | 30 |
| 31 protected: | 31 protected: |
| 32 void neuter() override { | 32 void neuter() override { |
| 33 ArrayBufferView::neuter(); | 33 ArrayBufferView::neuter(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 61 return v8::Local<v8::Object>(); | 61 return v8::Local<v8::Object>(); |
| 62 DCHECK(v8Buffer->IsArrayBuffer()); | 62 DCHECK(v8Buffer->IsArrayBuffer()); |
| 63 | 63 |
| 64 v8::Local<v8::Object> wrapper = v8::DataView::New( | 64 v8::Local<v8::Object> wrapper = v8::DataView::New( |
| 65 v8Buffer.As<v8::ArrayBuffer>(), byteOffset(), byteLength()); | 65 v8Buffer.As<v8::ArrayBuffer>(), byteOffset(), byteLength()); |
| 66 | 66 |
| 67 return associateWithWrapper(isolate, wrapperTypeInfo, wrapper); | 67 return associateWithWrapper(isolate, wrapperTypeInfo, wrapper); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace blink | 70 } // namespace blink |
| OLD | NEW |