| OLD | NEW |
| 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 #include "src/v8.h" |
| 13 | 14 |
| 14 using namespace v8::internal; | 15 using namespace v8::internal; |
| 15 | 16 |
| 16 void TestArrayBufferViewContents(LocalContext& env, bool should_use_buffer) { | 17 void TestArrayBufferViewContents(LocalContext& env, bool should_use_buffer) { |
| 17 v8::Local<v8::Object> obj_a = | 18 v8::Local<v8::Object> obj_a = |
| 18 v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a"))); | 19 v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a"))); |
| 19 CHECK(obj_a->IsArrayBufferView()); | 20 CHECK(obj_a->IsArrayBufferView()); |
| 20 v8::Local<v8::ArrayBufferView> array_buffer_view = | 21 v8::Local<v8::ArrayBufferView> array_buffer_view = |
| 21 v8::Local<v8::ArrayBufferView>::Cast(obj_a); | 22 v8::Local<v8::ArrayBufferView>::Cast(obj_a); |
| 22 CHECK_EQ(array_buffer_view->HasBuffer(), should_use_buffer); | 23 CHECK_EQ(array_buffer_view->HasBuffer(), should_use_buffer); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 "var c = new Uint8Array(b);" | 60 "var c = new Uint8Array(b);" |
| 60 "c[0] = -1;" | 61 "c[0] = -1;" |
| 61 "c[1] = -1;" | 62 "c[1] = -1;" |
| 62 "c[2] = 0;" | 63 "c[2] = 0;" |
| 63 "c[3] = 1;" | 64 "c[3] = 1;" |
| 64 "c[4] = 2;" | 65 "c[4] = 2;" |
| 65 "c[5] = 3;" | 66 "c[5] = 3;" |
| 66 "var a = new DataView(b, 2);"); | 67 "var a = new DataView(b, 2);"); |
| 67 TestArrayBufferViewContents(env, true); | 68 TestArrayBufferViewContents(env, true); |
| 68 } | 69 } |
| 70 |
| 71 |
| 72 TEST(AllocateNotExternal) { |
| 73 LocalContext env; |
| 74 v8::HandleScope scope(env->GetIsolate()); |
| 75 void* memory = V8::ArrayBufferAllocator()->Allocate(1024); |
| 76 v8::Local<v8::ArrayBuffer> buffer = |
| 77 v8::ArrayBuffer::New(env->GetIsolate(), memory, 1024, false); |
| 78 CHECK(!buffer->IsExternal()); |
| 79 CHECK_EQ(memory, buffer->GetContents().Data()); |
| 80 } |
| OLD | NEW |