Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdlib.h> | |
| 6 | |
| 7 #include "src/v8.h" | |
| 8 #include "test/cctest/cctest.h" | |
| 9 | |
| 10 #include "src/api.h" | |
| 11 #include "src/heap/heap.h" | |
| 12 #include "src/objects.h" | |
| 13 | |
| 14 using namespace v8::internal; | |
| 15 | |
| 16 void TestArrayBufferViewContents(LocalContext& env) { | |
| 17 v8::Local<v8::Object> obj_a = | |
| 18 v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a"))); | |
| 19 CHECK(obj_a->IsArrayBufferView()); | |
| 20 v8::Local<v8::ArrayBufferView> array_buffer_view = | |
| 21 v8::Local<v8::ArrayBufferView>::Cast(obj_a); | |
| 22 Handle<JSArrayBufferView> internal_view( | |
| 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 unsigned char contents[4] = {23, 23, 23, 23}; | |
| 30 CHECK_EQ(sizeof(contents), | |
| 31 array_buffer_view->CopyContents(contents, sizeof(contents))); | |
| 32 if (!has_buffer) { | |
| 33 CHECK(internal_view->IsJSTypedArray()); | |
| 34 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*internal_view)); | |
| 35 CHECK(typed_array->buffer()->IsSmi()); | |
| 36 } | |
| 37 for (size_t i = 0; i < sizeof(contents); ++i) { | |
| 38 CHECK_EQ(i, contents[i]); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 | |
| 43 TEST(CopyContentsTypedArray) { | |
| 44 LocalContext env; | |
| 45 v8::HandleScope scope(env->GetIsolate()); | |
| 46 CompileRun( | |
| 47 "var a = new Uint8Array(4);" | |
|
jochen (gone - plz use gerrit)
2015/03/31 16:40:27
this is actually the only case that creates an on-
| |
| 48 "a[0] = 0;" | |
| 49 "a[1] = 1;" | |
| 50 "a[2] = 2;" | |
| 51 "a[3] = 3;"); | |
| 52 TestArrayBufferViewContents(env); | |
| 53 } | |
| 54 | |
| 55 | |
| 56 TEST(CopyContentsArray) { | |
| 57 LocalContext env; | |
| 58 v8::HandleScope scope(env->GetIsolate()); | |
| 59 CompileRun("var a = new Uint8Array([0, 1, 2, 3]);"); | |
| 60 TestArrayBufferViewContents(env); | |
| 61 } | |
| 62 | |
| 63 | |
| 64 TEST(CopyContentsView) { | |
| 65 LocalContext env; | |
| 66 v8::HandleScope scope(env->GetIsolate()); | |
| 67 CompileRun( | |
| 68 "var b = new ArrayBuffer(6);" | |
| 69 "var c = new Uint8Array(b);" | |
| 70 "c[0] = -1;" | |
| 71 "c[1] = -1;" | |
| 72 "c[2] = 0;" | |
| 73 "c[3] = 1;" | |
| 74 "c[4] = 2;" | |
| 75 "c[5] = 3;" | |
| 76 "var a = new DataView(b, 2);"); | |
| 77 TestArrayBufferViewContents(env); | |
| 78 } | |
| OLD | NEW |