OLD | NEW |
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 2828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2839 CheckIsTypedArrayVarNeutered("u32a"); | 2839 CheckIsTypedArrayVarNeutered("u32a"); |
2840 CheckIsTypedArrayVarNeutered("i32a"); | 2840 CheckIsTypedArrayVarNeutered("i32a"); |
2841 CheckIsTypedArrayVarNeutered("f32a"); | 2841 CheckIsTypedArrayVarNeutered("f32a"); |
2842 CheckIsTypedArrayVarNeutered("f64a"); | 2842 CheckIsTypedArrayVarNeutered("f64a"); |
2843 | 2843 |
2844 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); | 2844 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); |
2845 CheckDataViewIsNeutered(dv); | 2845 CheckDataViewIsNeutered(dv); |
2846 } | 2846 } |
2847 | 2847 |
2848 | 2848 |
| 2849 class ScopedSharedArrayBufferContents { |
| 2850 public: |
| 2851 explicit ScopedSharedArrayBufferContents( |
| 2852 const v8::SharedArrayBuffer::Contents& contents) |
| 2853 : contents_(contents) {} |
| 2854 ~ScopedSharedArrayBufferContents() { free(contents_.Data()); } |
| 2855 void* Data() const { return contents_.Data(); } |
| 2856 size_t ByteLength() const { return contents_.ByteLength(); } |
| 2857 |
| 2858 private: |
| 2859 const v8::SharedArrayBuffer::Contents contents_; |
| 2860 }; |
| 2861 |
| 2862 |
| 2863 THREADED_TEST(SharedArrayBuffer_ApiInternalToExternal) { |
| 2864 i::FLAG_harmony_sharedarraybuffer = true; |
| 2865 LocalContext env; |
| 2866 v8::Isolate* isolate = env->GetIsolate(); |
| 2867 v8::HandleScope handle_scope(isolate); |
| 2868 |
| 2869 Local<v8::SharedArrayBuffer> ab = v8::SharedArrayBuffer::New(isolate, 1024); |
| 2870 CheckInternalFieldsAreZero(ab); |
| 2871 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); |
| 2872 CHECK(!ab->IsExternal()); |
| 2873 CcTest::heap()->CollectAllGarbage(); |
| 2874 |
| 2875 ScopedSharedArrayBufferContents ab_contents(ab->Externalize()); |
| 2876 CHECK(ab->IsExternal()); |
| 2877 |
| 2878 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); |
| 2879 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); |
| 2880 DCHECK(data != NULL); |
| 2881 env->Global()->Set(v8_str("ab"), ab); |
| 2882 |
| 2883 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); |
| 2884 CHECK_EQ(1024, result->Int32Value()); |
| 2885 |
| 2886 result = CompileRun( |
| 2887 "var u8 = new Uint8Array(ab);" |
| 2888 "u8[0] = 0xFF;" |
| 2889 "u8[1] = 0xAA;" |
| 2890 "u8.length"); |
| 2891 CHECK_EQ(1024, result->Int32Value()); |
| 2892 CHECK_EQ(0xFF, data[0]); |
| 2893 CHECK_EQ(0xAA, data[1]); |
| 2894 data[0] = 0xCC; |
| 2895 data[1] = 0x11; |
| 2896 result = CompileRun("u8[0] + u8[1]"); |
| 2897 CHECK_EQ(0xDD, result->Int32Value()); |
| 2898 } |
| 2899 |
| 2900 |
| 2901 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) { |
| 2902 i::FLAG_harmony_sharedarraybuffer = true; |
| 2903 LocalContext env; |
| 2904 v8::Isolate* isolate = env->GetIsolate(); |
| 2905 v8::HandleScope handle_scope(isolate); |
| 2906 |
| 2907 |
| 2908 v8::Local<v8::Value> result = CompileRun( |
| 2909 "var ab1 = new SharedArrayBuffer(2);" |
| 2910 "var u8_a = new Uint8Array(ab1);" |
| 2911 "u8_a[0] = 0xAA;" |
| 2912 "u8_a[1] = 0xFF; u8_a.buffer"); |
| 2913 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result); |
| 2914 CheckInternalFieldsAreZero(ab1); |
| 2915 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); |
| 2916 CHECK(!ab1->IsExternal()); |
| 2917 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize()); |
| 2918 CHECK(ab1->IsExternal()); |
| 2919 |
| 2920 result = CompileRun("ab1.byteLength"); |
| 2921 CHECK_EQ(2, result->Int32Value()); |
| 2922 result = CompileRun("u8_a[0]"); |
| 2923 CHECK_EQ(0xAA, result->Int32Value()); |
| 2924 result = CompileRun("u8_a[1]"); |
| 2925 CHECK_EQ(0xFF, result->Int32Value()); |
| 2926 result = CompileRun( |
| 2927 "var u8_b = new Uint8Array(ab1);" |
| 2928 "u8_b[0] = 0xBB;" |
| 2929 "u8_a[0]"); |
| 2930 CHECK_EQ(0xBB, result->Int32Value()); |
| 2931 result = CompileRun("u8_b[1]"); |
| 2932 CHECK_EQ(0xFF, result->Int32Value()); |
| 2933 |
| 2934 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); |
| 2935 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); |
| 2936 CHECK_EQ(0xBB, ab1_data[0]); |
| 2937 CHECK_EQ(0xFF, ab1_data[1]); |
| 2938 ab1_data[0] = 0xCC; |
| 2939 ab1_data[1] = 0x11; |
| 2940 result = CompileRun("u8_a[0] + u8_a[1]"); |
| 2941 CHECK_EQ(0xDD, result->Int32Value()); |
| 2942 } |
| 2943 |
| 2944 |
| 2945 THREADED_TEST(SharedArrayBuffer_External) { |
| 2946 i::FLAG_harmony_sharedarraybuffer = true; |
| 2947 LocalContext env; |
| 2948 v8::Isolate* isolate = env->GetIsolate(); |
| 2949 v8::HandleScope handle_scope(isolate); |
| 2950 |
| 2951 i::ScopedVector<uint8_t> my_data(100); |
| 2952 memset(my_data.start(), 0, 100); |
| 2953 Local<v8::SharedArrayBuffer> ab3 = |
| 2954 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100); |
| 2955 CheckInternalFieldsAreZero(ab3); |
| 2956 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); |
| 2957 CHECK(ab3->IsExternal()); |
| 2958 |
| 2959 env->Global()->Set(v8_str("ab3"), ab3); |
| 2960 |
| 2961 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); |
| 2962 CHECK_EQ(100, result->Int32Value()); |
| 2963 |
| 2964 result = CompileRun( |
| 2965 "var u8_b = new Uint8Array(ab3);" |
| 2966 "u8_b[0] = 0xBB;" |
| 2967 "u8_b[1] = 0xCC;" |
| 2968 "u8_b.length"); |
| 2969 CHECK_EQ(100, result->Int32Value()); |
| 2970 CHECK_EQ(0xBB, my_data[0]); |
| 2971 CHECK_EQ(0xCC, my_data[1]); |
| 2972 my_data[0] = 0xCC; |
| 2973 my_data[1] = 0x11; |
| 2974 result = CompileRun("u8_b[0] + u8_b[1]"); |
| 2975 CHECK_EQ(0xDD, result->Int32Value()); |
| 2976 } |
| 2977 |
| 2978 |
2849 THREADED_TEST(HiddenProperties) { | 2979 THREADED_TEST(HiddenProperties) { |
2850 LocalContext env; | 2980 LocalContext env; |
2851 v8::Isolate* isolate = env->GetIsolate(); | 2981 v8::Isolate* isolate = env->GetIsolate(); |
2852 v8::HandleScope scope(isolate); | 2982 v8::HandleScope scope(isolate); |
2853 | 2983 |
2854 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); | 2984 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); |
2855 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 2985 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
2856 v8::Local<v8::String> empty = v8_str(""); | 2986 v8::Local<v8::String> empty = v8_str(""); |
2857 v8::Local<v8::String> prop_name = v8_str("prop_name"); | 2987 v8::Local<v8::String> prop_name = v8_str("prop_name"); |
2858 | 2988 |
(...skipping 18258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21117 // add the testExtraShouldReturnFive export | 21247 // add the testExtraShouldReturnFive export |
21118 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); | 21248 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); |
21119 | 21249 |
21120 auto func = | 21250 auto func = |
21121 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); | 21251 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); |
21122 auto undefined = v8::Undefined(isolate); | 21252 auto undefined = v8::Undefined(isolate); |
21123 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 21253 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); |
21124 | 21254 |
21125 CHECK(result->Value() == 5.0); | 21255 CHECK(result->Value() == 5.0); |
21126 } | 21256 } |
OLD | NEW |