OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "test/cctest/test-api.h" | 7 #include "test/cctest/test-api.h" |
8 | 8 |
9 #include "include/v8-util.h" | 9 #include "include/v8-util.h" |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2874 CHECK(v8_str("x")->Equals(result_array->Get(1))); | 2874 CHECK(v8_str("x")->Equals(result_array->Get(1))); |
2875 | 2875 |
2876 result = CompileRun("Object.getOwnPropertySymbols(object)"); | 2876 result = CompileRun("Object.getOwnPropertySymbols(object)"); |
2877 CHECK(result->IsArray()); | 2877 CHECK(result->IsArray()); |
2878 result_array = v8::Handle<v8::Array>::Cast(result); | 2878 result_array = v8::Handle<v8::Array>::Cast(result); |
2879 CHECK_EQ(1u, result_array->Length()); | 2879 CHECK_EQ(1u, result_array->Length()); |
2880 CHECK(result_array->Get(0)->Equals(v8::Symbol::GetIterator(isolate))); | 2880 CHECK(result_array->Get(0)->Equals(v8::Symbol::GetIterator(isolate))); |
2881 } | 2881 } |
2882 | 2882 |
2883 | 2883 |
2884 static void IndexedPropertyEnumeratorException( | |
2885 const v8::PropertyCallbackInfo<v8::Array>& info) { | |
2886 info.GetIsolate()->ThrowException(v8_num(42)); | |
2887 } | |
2888 | |
2889 | |
2890 THREADED_TEST(GetOwnPropertyNamesWithIndexedInterceptorExceptions_regress4026) { | |
2891 v8::Isolate* isolate = CcTest::isolate(); | |
2892 v8::HandleScope handle_scope(isolate); | |
2893 v8::Handle<v8::ObjectTemplate> obj_template = | |
2894 v8::ObjectTemplate::New(isolate); | |
2895 | |
2896 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); | |
2897 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); | |
2898 // First just try a failing indexed interceptor. | |
2899 obj_template->SetHandler(v8::IndexedPropertyHandlerConfiguration( | |
2900 NULL, NULL, NULL, NULL, IndexedPropertyEnumeratorException)); | |
2901 | |
2902 LocalContext context; | |
2903 v8::Handle<v8::Object> global = context->Global(); | |
2904 global->Set(v8_str("object"), obj_template->NewInstance()); | |
2905 v8::Handle<v8::Value> result = CompileRun( | |
2906 "var ret = []; " | |
2907 "try { " | |
2908 " for (var k in object) ret.push(k);" | |
2909 "} catch (e) {" | |
2910 " ret = e" | |
Jakob Kummerow
2015/10/26 16:12:27
nit: indentation :-)
| |
2911 "}" | |
2912 "ret"); | |
2913 CHECK(!result->IsArray()); | |
2914 CHECK(v8_num(42)->Equals(result)); | |
2915 | |
2916 result = CompileRun( | |
2917 "var result = [];" | |
2918 "try { " | |
2919 " result = Object.keys(object);" | |
2920 "} catch (e) {" | |
2921 " result = e;" | |
2922 "}" | |
2923 "result"); | |
2924 CHECK(!result->IsArray()); | |
2925 CHECK(v8_num(42)->Equals(result)); | |
2926 } | |
2927 | |
2928 | |
2929 static void NamedPropertyEnumeratorException( | |
2930 const v8::PropertyCallbackInfo<v8::Array>& info) { | |
2931 info.GetIsolate()->ThrowException(v8_num(43)); | |
2932 } | |
2933 | |
2934 | |
2935 THREADED_TEST(GetOwnPropertyNamesWithNamedInterceptorExceptions_regress4026) { | |
2936 v8::Isolate* isolate = CcTest::isolate(); | |
2937 v8::HandleScope handle_scope(isolate); | |
2938 v8::Handle<v8::ObjectTemplate> obj_template = | |
2939 v8::ObjectTemplate::New(isolate); | |
2940 | |
2941 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); | |
2942 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); | |
2943 // First just try a failing indexed interceptor. | |
2944 obj_template->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
2945 NULL, NULL, NULL, NULL, NamedPropertyEnumeratorException)); | |
2946 | |
2947 LocalContext context; | |
2948 v8::Handle<v8::Object> global = context->Global(); | |
2949 global->Set(v8_str("object"), obj_template->NewInstance()); | |
2950 | |
2951 v8::Handle<v8::Value> result = CompileRun( | |
2952 "var result = []; " | |
2953 "try { " | |
2954 " for (var k in object) result.push(k);" | |
2955 "} catch (e) {" | |
2956 " result = e" | |
Jakob Kummerow
2015/10/26 16:12:27
again
| |
2957 "}" | |
2958 "result"); | |
2959 CHECK(!result->IsArray()); | |
2960 CHECK(v8_num(43)->Equals(result)); | |
2961 | |
2962 result = CompileRun( | |
2963 "var result = [];" | |
2964 "try { " | |
2965 " result = Object.keys(object);" | |
2966 "} catch (e) {" | |
2967 " result = e;" | |
2968 "}" | |
2969 "result"); | |
2970 CHECK(!result->IsArray()); | |
2971 CHECK(v8_num(43)->Equals(result)); | |
2972 } | |
2973 | |
2884 namespace { | 2974 namespace { |
2885 | 2975 |
2886 template <typename T> | 2976 template <typename T> |
2887 Local<Object> BuildWrappedObject(v8::Isolate* isolate, T* data) { | 2977 Local<Object> BuildWrappedObject(v8::Isolate* isolate, T* data) { |
2888 auto templ = v8::ObjectTemplate::New(isolate); | 2978 auto templ = v8::ObjectTemplate::New(isolate); |
2889 templ->SetInternalFieldCount(1); | 2979 templ->SetInternalFieldCount(1); |
2890 auto instance = templ->NewInstance(); | 2980 auto instance = templ->NewInstance(); |
2891 instance->SetAlignedPointerInInternalField(0, data); | 2981 instance->SetAlignedPointerInInternalField(0, data); |
2892 return instance; | 2982 return instance; |
2893 } | 2983 } |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3281 "var obj = intercepted_1;" | 3371 "var obj = intercepted_1;" |
3282 "obj.x = 4;" | 3372 "obj.x = 4;" |
3283 "eval('obj.x');" | 3373 "eval('obj.x');" |
3284 "eval('obj.x');" | 3374 "eval('obj.x');" |
3285 "eval('obj.x');" | 3375 "eval('obj.x');" |
3286 "obj = intercepted_2;" | 3376 "obj = intercepted_2;" |
3287 "obj.x = 9;" | 3377 "obj.x = 9;" |
3288 "eval('obj.x');", | 3378 "eval('obj.x');", |
3289 9); | 3379 9); |
3290 } | 3380 } |
OLD | NEW |