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

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

Issue 1136553006: Implement SharedArrayBuffer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge master Created 5 years, 7 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
« no previous file with comments | « src/typedarray.js ('k') | test/mjsunit/harmony/sharedarraybuffer.js » ('j') | 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 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 CheckIsTypedArrayVarNeutered("u32a"); 2758 CheckIsTypedArrayVarNeutered("u32a");
2759 CheckIsTypedArrayVarNeutered("i32a"); 2759 CheckIsTypedArrayVarNeutered("i32a");
2760 CheckIsTypedArrayVarNeutered("f32a"); 2760 CheckIsTypedArrayVarNeutered("f32a");
2761 CheckIsTypedArrayVarNeutered("f64a"); 2761 CheckIsTypedArrayVarNeutered("f64a");
2762 2762
2763 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); 2763 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
2764 CheckDataViewIsNeutered(dv); 2764 CheckDataViewIsNeutered(dv);
2765 } 2765 }
2766 2766
2767 2767
2768 class ScopedSharedArrayBufferContents {
2769 public:
2770 explicit ScopedSharedArrayBufferContents(
2771 const v8::SharedArrayBuffer::Contents& contents)
2772 : contents_(contents) {}
2773 ~ScopedSharedArrayBufferContents() { free(contents_.Data()); }
2774 void* Data() const { return contents_.Data(); }
2775 size_t ByteLength() const { return contents_.ByteLength(); }
2776
2777 private:
2778 const v8::SharedArrayBuffer::Contents contents_;
2779 };
2780
2781
2782 THREADED_TEST(SharedArrayBuffer_ApiInternalToExternal) {
2783 i::FLAG_harmony_sharedarraybuffer = true;
2784 LocalContext env;
2785 v8::Isolate* isolate = env->GetIsolate();
2786 v8::HandleScope handle_scope(isolate);
2787
2788 Local<v8::SharedArrayBuffer> ab = v8::SharedArrayBuffer::New(isolate, 1024);
2789 CheckInternalFieldsAreZero(ab);
2790 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2791 CHECK(!ab->IsExternal());
2792 CcTest::heap()->CollectAllGarbage();
2793
2794 ScopedSharedArrayBufferContents ab_contents(ab->Externalize());
2795 CHECK(ab->IsExternal());
2796
2797 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2798 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2799 DCHECK(data != NULL);
2800 env->Global()->Set(v8_str("ab"), ab);
2801
2802 v8::Handle<v8::Value> result = CompileRun("ab.byteLength");
2803 CHECK_EQ(1024, result->Int32Value());
2804
2805 result = CompileRun(
2806 "var u8 = new Uint8Array(ab);"
2807 "u8[0] = 0xFF;"
2808 "u8[1] = 0xAA;"
2809 "u8.length");
2810 CHECK_EQ(1024, result->Int32Value());
2811 CHECK_EQ(0xFF, data[0]);
2812 CHECK_EQ(0xAA, data[1]);
2813 data[0] = 0xCC;
2814 data[1] = 0x11;
2815 result = CompileRun("u8[0] + u8[1]");
2816 CHECK_EQ(0xDD, result->Int32Value());
2817 }
2818
2819
2820 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) {
2821 i::FLAG_harmony_sharedarraybuffer = true;
2822 LocalContext env;
2823 v8::Isolate* isolate = env->GetIsolate();
2824 v8::HandleScope handle_scope(isolate);
2825
2826
2827 v8::Local<v8::Value> result = CompileRun(
2828 "var ab1 = new SharedArrayBuffer(2);"
2829 "var u8_a = new Uint8Array(ab1);"
2830 "u8_a[0] = 0xAA;"
2831 "u8_a[1] = 0xFF; u8_a.buffer");
2832 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result);
2833 CheckInternalFieldsAreZero(ab1);
2834 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2835 CHECK(!ab1->IsExternal());
2836 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize());
2837 CHECK(ab1->IsExternal());
2838
2839 result = CompileRun("ab1.byteLength");
2840 CHECK_EQ(2, result->Int32Value());
2841 result = CompileRun("u8_a[0]");
2842 CHECK_EQ(0xAA, result->Int32Value());
2843 result = CompileRun("u8_a[1]");
2844 CHECK_EQ(0xFF, result->Int32Value());
2845 result = CompileRun(
2846 "var u8_b = new Uint8Array(ab1);"
2847 "u8_b[0] = 0xBB;"
2848 "u8_a[0]");
2849 CHECK_EQ(0xBB, result->Int32Value());
2850 result = CompileRun("u8_b[1]");
2851 CHECK_EQ(0xFF, result->Int32Value());
2852
2853 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
2854 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
2855 CHECK_EQ(0xBB, ab1_data[0]);
2856 CHECK_EQ(0xFF, ab1_data[1]);
2857 ab1_data[0] = 0xCC;
2858 ab1_data[1] = 0x11;
2859 result = CompileRun("u8_a[0] + u8_a[1]");
2860 CHECK_EQ(0xDD, result->Int32Value());
2861 }
2862
2863
2864 THREADED_TEST(SharedArrayBuffer_External) {
2865 i::FLAG_harmony_sharedarraybuffer = true;
2866 LocalContext env;
2867 v8::Isolate* isolate = env->GetIsolate();
2868 v8::HandleScope handle_scope(isolate);
2869
2870 i::ScopedVector<uint8_t> my_data(100);
2871 memset(my_data.start(), 0, 100);
2872 Local<v8::SharedArrayBuffer> ab3 =
2873 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100);
2874 CheckInternalFieldsAreZero(ab3);
2875 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2876 CHECK(ab3->IsExternal());
2877
2878 env->Global()->Set(v8_str("ab3"), ab3);
2879
2880 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength");
2881 CHECK_EQ(100, result->Int32Value());
2882
2883 result = CompileRun(
2884 "var u8_b = new Uint8Array(ab3);"
2885 "u8_b[0] = 0xBB;"
2886 "u8_b[1] = 0xCC;"
2887 "u8_b.length");
2888 CHECK_EQ(100, result->Int32Value());
2889 CHECK_EQ(0xBB, my_data[0]);
2890 CHECK_EQ(0xCC, my_data[1]);
2891 my_data[0] = 0xCC;
2892 my_data[1] = 0x11;
2893 result = CompileRun("u8_b[0] + u8_b[1]");
2894 CHECK_EQ(0xDD, result->Int32Value());
2895 }
2896
2897
2768 THREADED_TEST(HiddenProperties) { 2898 THREADED_TEST(HiddenProperties) {
2769 LocalContext env; 2899 LocalContext env;
2770 v8::Isolate* isolate = env->GetIsolate(); 2900 v8::Isolate* isolate = env->GetIsolate();
2771 v8::HandleScope scope(isolate); 2901 v8::HandleScope scope(isolate);
2772 2902
2773 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 2903 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
2774 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2904 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2775 v8::Local<v8::String> empty = v8_str(""); 2905 v8::Local<v8::String> empty = v8_str("");
2776 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2906 v8::Local<v8::String> prop_name = v8_str("prop_name");
2777 2907
(...skipping 18258 matching lines...) Expand 10 before | Expand all | Expand 10 after
21036 // add the testExtraShouldReturnFive export 21166 // add the testExtraShouldReturnFive export
21037 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); 21167 v8::Local<v8::Object> exports = env->GetExtrasExportsObject();
21038 21168
21039 auto func = 21169 auto func =
21040 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); 21170 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>();
21041 auto undefined = v8::Undefined(isolate); 21171 auto undefined = v8::Undefined(isolate);
21042 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); 21172 auto result = func->Call(undefined, 0, {}).As<v8::Number>();
21043 21173
21044 CHECK(result->Value() == 5.0); 21174 CHECK(result->Value() == 5.0);
21045 } 21175 }
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | test/mjsunit/harmony/sharedarraybuffer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698