Skip to content

Commit

Permalink
Version 4.3.61.16 (cherry-pick)
Browse files Browse the repository at this point in the history
Merged ada32ae

Expose ArrayBufferView::HasBuffer

BUG=v8:3996
LOG=N
R=danno@chromium.org

Review URL: https://codereview.chromium.org/1110713004

Cr-Commit-Position: refs/branch-heads/4.3@{crosswalk-project#19}
Cr-Branched-From: f5c0a23-refs/heads/4.3.61@{#1}
Cr-Branched-From: 0a7d4f4-refs/heads/master@{#27508}
  • Loading branch information
jeisinger committed Apr 30, 2015
1 parent b33a56c commit 92a4588
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 4
#define V8_MINOR_VERSION 3
#define V8_BUILD_NUMBER 61
#define V8_PATCH_LEVEL 15
#define V8_PATCH_LEVEL 16

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
6 changes: 6 additions & 0 deletions include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,12 @@ class V8_EXPORT ArrayBufferView : public Object {
*/
size_t CopyContents(void* dest, size_t byte_length);

/**
* Returns true if ArrayBufferView's backing ArrayBuffer has already been
* allocated.
*/
bool HasBuffer() const;

V8_INLINE static ArrayBufferView* Cast(Value* obj);

static const int kInternalFieldCount =
Expand Down
9 changes: 9 additions & 0 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6466,6 +6466,15 @@ size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) {
}


bool v8::ArrayBufferView::HasBuffer() const {
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
if (obj->IsJSDataView()) return true;
DCHECK(obj->IsJSTypedArray());
i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*obj));
return !typed_array->buffer()->IsSmi();
}


size_t v8::ArrayBufferView::ByteOffset() {
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
return static_cast<size_t>(obj->byte_offset()->Number());
Expand Down
15 changes: 2 additions & 13 deletions test/cctest/test-typedarrays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@ void TestArrayBufferViewContents(LocalContext& env, bool should_use_buffer) {
CHECK(obj_a->IsArrayBufferView());
v8::Local<v8::ArrayBufferView> array_buffer_view =
v8::Local<v8::ArrayBufferView>::Cast(obj_a);
Handle<JSArrayBufferView> internal_view(
v8::Utils::OpenHandle(*array_buffer_view));
bool has_buffer = true;
if (internal_view->IsJSTypedArray()) {
Handle<JSTypedArray> typed_array(JSTypedArray::cast(*internal_view));
has_buffer = !typed_array->buffer()->IsSmi();
}
CHECK_EQ(has_buffer, should_use_buffer);
CHECK_EQ(array_buffer_view->HasBuffer(), should_use_buffer);
unsigned char contents[4] = {23, 23, 23, 23};
CHECK_EQ(sizeof(contents),
array_buffer_view->CopyContents(contents, sizeof(contents)));
if (!has_buffer) {
CHECK(internal_view->IsJSTypedArray());
Handle<JSTypedArray> typed_array(JSTypedArray::cast(*internal_view));
CHECK(typed_array->buffer()->IsSmi());
}
CHECK_EQ(array_buffer_view->HasBuffer(), should_use_buffer);
for (size_t i = 0; i < sizeof(contents); ++i) {
CHECK_EQ(i, contents[i]);
}
Expand Down

0 comments on commit 92a4588

Please sign in to comment.