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

Side by Side Diff: test/cctest/test-typedarrays.cc

Issue 1084513002: Expose ArrayBufferView::HasBuffer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 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
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project 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 <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 #include "test/cctest/cctest.h" 8 #include "test/cctest/cctest.h"
9 9
10 #include "src/api.h" 10 #include "src/api.h"
11 #include "src/heap/heap.h" 11 #include "src/heap/heap.h"
12 #include "src/objects.h" 12 #include "src/objects.h"
13 13
14 using namespace v8::internal; 14 using namespace v8::internal;
15 15
16 void TestArrayBufferViewContents(LocalContext& env, bool should_use_buffer) { 16 void TestArrayBufferViewContents(LocalContext& env, bool should_use_buffer) {
17 v8::Local<v8::Object> obj_a = 17 v8::Local<v8::Object> obj_a =
18 v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a"))); 18 v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
19 CHECK(obj_a->IsArrayBufferView()); 19 CHECK(obj_a->IsArrayBufferView());
20 v8::Local<v8::ArrayBufferView> array_buffer_view = 20 v8::Local<v8::ArrayBufferView> array_buffer_view =
21 v8::Local<v8::ArrayBufferView>::Cast(obj_a); 21 v8::Local<v8::ArrayBufferView>::Cast(obj_a);
22 Handle<JSArrayBufferView> internal_view( 22 CHECK_EQ(array_buffer_view->HasBuffer(), should_use_buffer);
23 v8::Utils::OpenHandle(*array_buffer_view));
24 bool has_buffer = true;
25 if (internal_view->IsJSTypedArray()) {
26 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*internal_view));
27 has_buffer = !typed_array->buffer()->IsSmi();
28 }
29 CHECK_EQ(has_buffer, should_use_buffer);
30 unsigned char contents[4] = {23, 23, 23, 23}; 23 unsigned char contents[4] = {23, 23, 23, 23};
31 CHECK_EQ(sizeof(contents), 24 CHECK_EQ(sizeof(contents),
32 array_buffer_view->CopyContents(contents, sizeof(contents))); 25 array_buffer_view->CopyContents(contents, sizeof(contents)));
33 if (!has_buffer) { 26 CHECK_EQ(array_buffer_view->HasBuffer(), should_use_buffer);
34 CHECK(internal_view->IsJSTypedArray());
35 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*internal_view));
36 CHECK(typed_array->buffer()->IsSmi());
37 }
38 for (size_t i = 0; i < sizeof(contents); ++i) { 27 for (size_t i = 0; i < sizeof(contents); ++i) {
39 CHECK_EQ(i, contents[i]); 28 CHECK_EQ(i, contents[i]);
40 } 29 }
41 } 30 }
42 31
43 32
44 TEST(CopyContentsTypedArray) { 33 TEST(CopyContentsTypedArray) {
45 LocalContext env; 34 LocalContext env;
46 v8::HandleScope scope(env->GetIsolate()); 35 v8::HandleScope scope(env->GetIsolate());
47 CompileRun( 36 CompileRun(
(...skipping 22 matching lines...) Expand all
70 "var c = new Uint8Array(b);" 59 "var c = new Uint8Array(b);"
71 "c[0] = -1;" 60 "c[0] = -1;"
72 "c[1] = -1;" 61 "c[1] = -1;"
73 "c[2] = 0;" 62 "c[2] = 0;"
74 "c[3] = 1;" 63 "c[3] = 1;"
75 "c[4] = 2;" 64 "c[4] = 2;"
76 "c[5] = 3;" 65 "c[5] = 3;"
77 "var a = new DataView(b, 2);"); 66 "var a = new DataView(b, 2);");
78 TestArrayBufferViewContents(env, true); 67 TestArrayBufferViewContents(env, true);
79 } 68 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698