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

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: update MakeTypeError calls 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
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 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after
2834 CheckIsTypedArrayVarNeutered("u32a"); 2834 CheckIsTypedArrayVarNeutered("u32a");
2835 CheckIsTypedArrayVarNeutered("i32a"); 2835 CheckIsTypedArrayVarNeutered("i32a");
2836 CheckIsTypedArrayVarNeutered("f32a"); 2836 CheckIsTypedArrayVarNeutered("f32a");
2837 CheckIsTypedArrayVarNeutered("f64a"); 2837 CheckIsTypedArrayVarNeutered("f64a");
2838 2838
2839 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); 2839 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
2840 CheckDataViewIsNeutered(dv); 2840 CheckDataViewIsNeutered(dv);
2841 } 2841 }
2842 2842
2843 2843
2844 class ScopedSharedArrayBufferContents {
2845 public:
2846 explicit ScopedSharedArrayBufferContents(
2847 const v8::SharedArrayBuffer::Contents& contents)
2848 : contents_(contents) {}
2849 ~ScopedSharedArrayBufferContents() { free(contents_.Data()); }
2850 void* Data() const { return contents_.Data(); }
2851 size_t ByteLength() const { return contents_.ByteLength(); }
2852
2853 private:
2854 const v8::SharedArrayBuffer::Contents contents_;
2855 };
2856
2857
2858 THREADED_TEST(SharedArrayBuffer_ApiInternalToExternal) {
2859 i::FLAG_harmony_shared_typed_arrays = true;
2860 LocalContext env;
2861 v8::Isolate* isolate = env->GetIsolate();
2862 v8::HandleScope handle_scope(isolate);
2863
2864 Local<v8::SharedArrayBuffer> ab = v8::SharedArrayBuffer::New(isolate, 1024);
2865 CheckInternalFieldsAreZero(ab);
2866 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2867 CHECK(!ab->IsExternal());
2868 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2869
2870 ScopedSharedArrayBufferContents ab_contents(ab->Externalize());
2871 CHECK(ab->IsExternal());
2872
2873 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2874 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2875 DCHECK(data != NULL);
2876 env->Global()->Set(v8_str("ab"), ab);
2877
2878 v8::Handle<v8::Value> result = CompileRun("ab.byteLength");
2879 CHECK_EQ(1024, result->Int32Value());
2880
2881 result = CompileRun(
2882 "var u8 = new SharedUint8Array(ab);"
2883 "u8[0] = 0xFF;"
2884 "u8[1] = 0xAA;"
2885 "u8.length");
2886 CHECK_EQ(1024, result->Int32Value());
2887 CHECK_EQ(0xFF, data[0]);
2888 CHECK_EQ(0xAA, data[1]);
2889 data[0] = 0xCC;
2890 data[1] = 0x11;
2891 result = CompileRun("u8[0] + u8[1]");
2892 CHECK_EQ(0xDD, result->Int32Value());
2893 }
2894
2895
2896 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) {
2897 i::FLAG_harmony_shared_typed_arrays = true;
2898 LocalContext env;
2899 v8::Isolate* isolate = env->GetIsolate();
2900 v8::HandleScope handle_scope(isolate);
2901
2902
2903 v8::Local<v8::Value> result = CompileRun(
2904 "var ab1 = new SharedArrayBuffer(2);"
2905 "var u8_a = new SharedUint8Array(ab1);"
2906 "u8_a[0] = 0xAA;"
2907 "u8_a[1] = 0xFF; u8_a.buffer");
2908 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result);
2909 CheckInternalFieldsAreZero(ab1);
2910 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2911 CHECK(!ab1->IsExternal());
2912 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize());
2913 CHECK(ab1->IsExternal());
2914
2915 result = CompileRun("ab1.byteLength");
2916 CHECK_EQ(2, result->Int32Value());
2917 result = CompileRun("u8_a[0]");
2918 CHECK_EQ(0xAA, result->Int32Value());
2919 result = CompileRun("u8_a[1]");
2920 CHECK_EQ(0xFF, result->Int32Value());
2921 result = CompileRun(
2922 "var u8_b = new SharedUint8Array(ab1);"
2923 "u8_b[0] = 0xBB;"
2924 "u8_a[0]");
2925 CHECK_EQ(0xBB, result->Int32Value());
2926 result = CompileRun("u8_b[1]");
2927 CHECK_EQ(0xFF, result->Int32Value());
2928
2929 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
2930 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
2931 CHECK_EQ(0xBB, ab1_data[0]);
2932 CHECK_EQ(0xFF, ab1_data[1]);
2933 ab1_data[0] = 0xCC;
2934 ab1_data[1] = 0x11;
2935 result = CompileRun("u8_a[0] + u8_a[1]");
2936 CHECK_EQ(0xDD, result->Int32Value());
2937 }
2938
2939
2940 THREADED_TEST(SharedArrayBuffer_External) {
2941 i::FLAG_harmony_shared_typed_arrays = true;
2942 LocalContext env;
2943 v8::Isolate* isolate = env->GetIsolate();
2944 v8::HandleScope handle_scope(isolate);
2945
2946 i::ScopedVector<uint8_t> my_data(100);
2947 memset(my_data.start(), 0, 100);
2948 Local<v8::SharedArrayBuffer> ab3 =
2949 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100);
2950 CheckInternalFieldsAreZero(ab3);
2951 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2952 CHECK(ab3->IsExternal());
2953
2954 env->Global()->Set(v8_str("ab3"), ab3);
2955
2956 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength");
2957 CHECK_EQ(100, result->Int32Value());
2958
2959 result = CompileRun(
2960 "var u8_b = new SharedUint8Array(ab3);"
2961 "u8_b[0] = 0xBB;"
2962 "u8_b[1] = 0xCC;"
2963 "u8_b.length");
2964 CHECK_EQ(100, result->Int32Value());
2965 CHECK_EQ(0xBB, my_data[0]);
2966 CHECK_EQ(0xCC, my_data[1]);
2967 my_data[0] = 0xCC;
2968 my_data[1] = 0x11;
2969 result = CompileRun("u8_b[0] + u8_b[1]");
2970 CHECK_EQ(0xDD, result->Int32Value());
2971 }
2972
2973
2844 THREADED_TEST(HiddenProperties) { 2974 THREADED_TEST(HiddenProperties) {
2845 LocalContext env; 2975 LocalContext env;
2846 v8::Isolate* isolate = env->GetIsolate(); 2976 v8::Isolate* isolate = env->GetIsolate();
2847 v8::HandleScope scope(isolate); 2977 v8::HandleScope scope(isolate);
2848 2978
2849 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 2979 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
2850 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2980 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2851 v8::Local<v8::String> empty = v8_str(""); 2981 v8::Local<v8::String> empty = v8_str("");
2852 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2982 v8::Local<v8::String> prop_name = v8_str("prop_name");
2853 2983
(...skipping 18118 matching lines...) Expand 10 before | Expand all | Expand 10 after
20972 21102
20973 { 21103 {
20974 v8::HandleScope handle_scope(isolate); 21104 v8::HandleScope handle_scope(isolate);
20975 21105
20976 // Should work 21106 // Should work
20977 v8::Local<v8::Object> obj = v8::Object::New(isolate); 21107 v8::Local<v8::Object> obj = v8::Object::New(isolate);
20978 21108
20979 USE(obj); 21109 USE(obj);
20980 } 21110 }
20981 } 21111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698