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

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

Issue 1069883002: WIP SharedArrayBuffer implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« src/objects.h ('K') | « test/cctest/cctest.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2822 matching lines...) Expand 10 before | Expand all | Expand 10 after
2833 CheckIsTypedArrayVarNeutered("u32a"); 2833 CheckIsTypedArrayVarNeutered("u32a");
2834 CheckIsTypedArrayVarNeutered("i32a"); 2834 CheckIsTypedArrayVarNeutered("i32a");
2835 CheckIsTypedArrayVarNeutered("f32a"); 2835 CheckIsTypedArrayVarNeutered("f32a");
2836 CheckIsTypedArrayVarNeutered("f64a"); 2836 CheckIsTypedArrayVarNeutered("f64a");
2837 2837
2838 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); 2838 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
2839 CheckDataViewIsNeutered(dv); 2839 CheckDataViewIsNeutered(dv);
2840 } 2840 }
2841 2841
2842 2842
2843 class ScopedSharedArrayBufferContents {
2844 public:
2845 explicit ScopedSharedArrayBufferContents(
2846 const v8::SharedArrayBuffer::Contents& contents)
2847 : contents_(contents) {}
2848 ~ScopedSharedArrayBufferContents() { free(contents_.Data()); }
2849 void* Data() const { return contents_.Data(); }
2850 size_t ByteLength() const { return contents_.ByteLength(); }
2851
2852 private:
2853 const v8::SharedArrayBuffer::Contents contents_;
2854 };
2855
2856
2857 THREADED_TEST(SharedArrayBuffer_ApiInternalToExternal) {
2858 LocalContext env;
2859 v8::Isolate* isolate = env->GetIsolate();
2860 v8::HandleScope handle_scope(isolate);
2861
2862 Local<v8::SharedArrayBuffer> ab = v8::SharedArrayBuffer::New(isolate, 1024);
2863 CheckInternalFieldsAreZero(ab);
2864 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2865 CHECK(!ab->IsExternal());
2866 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2867
2868 ScopedSharedArrayBufferContents ab_contents(ab->Externalize());
2869 CHECK(ab->IsExternal());
2870
2871 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2872 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2873 DCHECK(data != NULL);
2874 env->Global()->Set(v8_str("ab"), ab);
2875
2876 v8::Handle<v8::Value> result = CompileRun("ab.byteLength");
2877 CHECK_EQ(1024, result->Int32Value());
2878
2879 result = CompileRun(
2880 "var u8 = new SharedUint8Array(ab);"
2881 "u8[0] = 0xFF;"
2882 "u8[1] = 0xAA;"
2883 "u8.length");
2884 CHECK_EQ(1024, result->Int32Value());
2885 CHECK_EQ(0xFF, data[0]);
2886 CHECK_EQ(0xAA, data[1]);
2887 data[0] = 0xCC;
2888 data[1] = 0x11;
2889 result = CompileRun("u8[0] + u8[1]");
2890 CHECK_EQ(0xDD, result->Int32Value());
2891 }
2892
2893
2894 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) {
2895 LocalContext env;
2896 v8::Isolate* isolate = env->GetIsolate();
2897 v8::HandleScope handle_scope(isolate);
2898
2899
2900 v8::Local<v8::Value> result = CompileRun(
2901 "var ab1 = new SharedArrayBuffer(2);"
2902 "var u8_a = new SharedUint8Array(ab1);"
2903 "u8_a[0] = 0xAA;"
2904 "u8_a[1] = 0xFF; u8_a.buffer");
2905 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result);
2906 CheckInternalFieldsAreZero(ab1);
2907 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2908 CHECK(!ab1->IsExternal());
2909 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize());
2910 CHECK(ab1->IsExternal());
2911
2912 result = CompileRun("ab1.byteLength");
2913 CHECK_EQ(2, result->Int32Value());
2914 result = CompileRun("u8_a[0]");
2915 CHECK_EQ(0xAA, result->Int32Value());
2916 result = CompileRun("u8_a[1]");
2917 CHECK_EQ(0xFF, result->Int32Value());
2918 result = CompileRun(
2919 "var u8_b = new SharedUint8Array(ab1);"
2920 "u8_b[0] = 0xBB;"
2921 "u8_a[0]");
2922 CHECK_EQ(0xBB, result->Int32Value());
2923 result = CompileRun("u8_b[1]");
2924 CHECK_EQ(0xFF, result->Int32Value());
2925
2926 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
2927 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
2928 CHECK_EQ(0xBB, ab1_data[0]);
2929 CHECK_EQ(0xFF, ab1_data[1]);
2930 ab1_data[0] = 0xCC;
2931 ab1_data[1] = 0x11;
2932 result = CompileRun("u8_a[0] + u8_a[1]");
2933 CHECK_EQ(0xDD, result->Int32Value());
2934 }
2935
2936
2937 THREADED_TEST(SharedArrayBuffer_External) {
2938 LocalContext env;
2939 v8::Isolate* isolate = env->GetIsolate();
2940 v8::HandleScope handle_scope(isolate);
2941
2942 i::ScopedVector<uint8_t> my_data(100);
2943 memset(my_data.start(), 0, 100);
2944 Local<v8::SharedArrayBuffer> ab3 =
2945 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100);
2946 CheckInternalFieldsAreZero(ab3);
2947 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2948 CHECK(ab3->IsExternal());
2949
2950 env->Global()->Set(v8_str("ab3"), ab3);
2951
2952 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength");
2953 CHECK_EQ(100, result->Int32Value());
2954
2955 result = CompileRun(
2956 "var u8_b = new SharedUint8Array(ab3);"
2957 "u8_b[0] = 0xBB;"
2958 "u8_b[1] = 0xCC;"
2959 "u8_b.length");
2960 CHECK_EQ(100, result->Int32Value());
2961 CHECK_EQ(0xBB, my_data[0]);
2962 CHECK_EQ(0xCC, my_data[1]);
2963 my_data[0] = 0xCC;
2964 my_data[1] = 0x11;
2965 result = CompileRun("u8_b[0] + u8_b[1]");
2966 CHECK_EQ(0xDD, result->Int32Value());
2967 }
2968
2969
2843 THREADED_TEST(HiddenProperties) { 2970 THREADED_TEST(HiddenProperties) {
2844 LocalContext env; 2971 LocalContext env;
2845 v8::Isolate* isolate = env->GetIsolate(); 2972 v8::Isolate* isolate = env->GetIsolate();
2846 v8::HandleScope scope(isolate); 2973 v8::HandleScope scope(isolate);
2847 2974
2848 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 2975 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
2849 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2976 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2850 v8::Local<v8::String> empty = v8_str(""); 2977 v8::Local<v8::String> empty = v8_str("");
2851 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2978 v8::Local<v8::String> prop_name = v8_str("prop_name");
2852 2979
(...skipping 19040 matching lines...) Expand 10 before | Expand all | Expand 10 after
21893 } 22020 }
21894 { 22021 {
21895 v8::TryCatch try_catch; 22022 v8::TryCatch try_catch;
21896 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); 22023 uint16_t* data = reinterpret_cast<uint16_t*>(buffer);
21897 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, 22024 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString,
21898 length).IsEmpty()); 22025 length).IsEmpty());
21899 CHECK(!try_catch.HasCaught()); 22026 CHECK(!try_catch.HasCaught());
21900 } 22027 }
21901 free(buffer); 22028 free(buffer);
21902 } 22029 }
OLDNEW
« src/objects.h ('K') | « test/cctest/cctest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698