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

Unified Diff: test/cctest/test-api.cc

Issue 16562005: Neutering API for v8::ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Style Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index cb34bed76cf085e7e9414d91d9bb56a41cf1f317..a59dd16f7c47548a61a9ef88a565d8f0e452a751 100755
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -2657,6 +2657,122 @@ THREADED_TEST(ArrayBuffer_External) {
}
+static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) {
+ CHECK_EQ(0, static_cast<int>(ta->ByteLength()));
+ CHECK_EQ(0, static_cast<int>(ta->Length()));
+ CHECK_EQ(0, static_cast<int>(ta->ByteOffset()));
+}
+
+template <typename TypedArray, int kElementSize>
+static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab,
+ int byteOffset,
Sven Panne 2013/06/07 12:21:08 Using size_t instead of int for offset/length is c
Dmitry Lomov (no reviews) 2013/06/07 14:57:09 No it does not get rid of casts - compiler gets co
+ int length) {
+ v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length);
+ CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset()));
+ CHECK_EQ(length, static_cast<int>(ta->Length()));
+ CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
+ return ta;
+}
+
+
+THREADED_TEST(ArrayBuffer_NeuteringApi) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope handle_scope(isolate);
+
+ v8::Handle<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(1024);
+
+ v8::Handle<v8::Uint8Array> u8a =
+ CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023);
+ v8::Handle<v8::Uint8ClampedArray> u8c =
+ CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023);
+ v8::Handle<v8::Int8Array> i8a =
+ CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023);
+
+ v8::Handle<v8::Uint16Array> u16a =
+ CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511);
+ v8::Handle<v8::Int16Array> i16a =
+ CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511);
+
+ v8::Handle<v8::Uint32Array> u32a =
+ CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
+ v8::Handle<v8::Int32Array> i32a =
+ CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
+
+ v8::Handle<v8::Float32Array> f32a =
+ CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
+ v8::Handle<v8::Float64Array> f64a =
+ CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
+
+ v8::ArrayBufferContents contents;
+ buffer->Externalize(&contents);
+ buffer->Neuter();
+ CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
+ CheckIsNeutered(u8a);
+ CheckIsNeutered(u8c);
+ CheckIsNeutered(i8a);
+ CheckIsNeutered(u16a);
+ CheckIsNeutered(i16a);
+ CheckIsNeutered(u32a);
+ CheckIsNeutered(i32a);
+ CheckIsNeutered(f32a);
+ CheckIsNeutered(f64a);
+}
+
+THREADED_TEST(ArrayBuffer_NeuteringScript) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope handle_scope(isolate);
+
+ CompileRun(
+ "var ab = new ArrayBuffer(1024);"
+ "var u8a = new Uint8Array(ab, 1, 1023);"
+ "var u8c = new Uint8ClampedArray(ab, 1, 1023);"
+ "var i8a = new Int8Array(ab, 1, 1023);"
+ "var u16a = new Uint16Array(ab, 2, 511);"
+ "var i16a = new Int16Array(ab, 2, 511);"
+ "var u32a = new Uint32Array(ab, 4, 255);"
+ "var i32a = new Int32Array(ab, 4, 255);"
+ "var f32a = new Float32Array(ab, 4, 255);"
+ "var f64a = new Float64Array(ab, 8, 127);");
+
+ v8::Handle<v8::ArrayBuffer> ab(v8::ArrayBuffer::Cast(*CompileRun("ab")));
+
+ v8::Handle<v8::Uint8Array> u8a(v8::Uint8Array::Cast(*CompileRun("u8a")));
+ v8::Handle<v8::Uint8ClampedArray> u8c(
+ v8::Uint8ClampedArray::Cast(*CompileRun("u8c")));
+ v8::Handle<v8::Int8Array> i8a(v8::Int8Array::Cast(*CompileRun("i8a")));
+
+ v8::Handle<v8::Uint16Array> u16a(
+ v8::Uint16Array::Cast(*CompileRun("u16a")));
+ v8::Handle<v8::Int16Array> i16a(
+ v8::Int16Array::Cast(*CompileRun("i16a")));
+ v8::Handle<v8::Uint32Array> u32a(
+ v8::Uint32Array::Cast(*CompileRun("u32a")));
+ v8::Handle<v8::Int32Array> i32a(
+ v8::Int32Array::Cast(*CompileRun("i32a")));
+ v8::Handle<v8::Float32Array> f32a(
+ v8::Float32Array::Cast(*CompileRun("f32a")));
+ v8::Handle<v8::Float64Array> f64a(
+ v8::Float64Array::Cast(*CompileRun("f64a")));
+
+ v8::ArrayBufferContents contents;
+ ab->Externalize(&contents);
+ ab->Neuter();
+ CHECK_EQ(0, static_cast<int>(ab->ByteLength()));
+ CheckIsNeutered(u8a);
+ CheckIsNeutered(u8c);
+ CheckIsNeutered(i8a);
+ CheckIsNeutered(u16a);
+ CheckIsNeutered(i16a);
+ CheckIsNeutered(u32a);
+ CheckIsNeutered(i32a);
+ CheckIsNeutered(f32a);
+ CheckIsNeutered(f64a);
+}
+
+
+
THREADED_TEST(HiddenProperties) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698