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 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 CHECK_EQ(v8_str("data"), info.Data()); | 1910 CHECK_EQ(v8_str("data"), info.Data()); |
1911 echo_named_call_count++; | 1911 echo_named_call_count++; |
1912 info.GetReturnValue().Set(name); | 1912 info.GetReturnValue().Set(name); |
1913 } | 1913 } |
1914 | 1914 |
1915 | 1915 |
1916 // Helper functions for Interceptor/Accessor interaction tests | 1916 // Helper functions for Interceptor/Accessor interaction tests |
1917 | 1917 |
1918 void SimpleAccessorGetter(Local<String> name, | 1918 void SimpleAccessorGetter(Local<String> name, |
1919 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1919 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1920 Handle<Object> self = info.This(); | 1920 Handle<Object> self = Handle<Object>::Cast(info.This()); |
1921 info.GetReturnValue().Set( | 1921 info.GetReturnValue().Set( |
1922 self->Get(String::Concat(v8_str("accessor_"), name))); | 1922 self->Get(String::Concat(v8_str("accessor_"), name))); |
1923 } | 1923 } |
1924 | 1924 |
1925 void SimpleAccessorSetter(Local<String> name, Local<Value> value, | 1925 void SimpleAccessorSetter(Local<String> name, Local<Value> value, |
1926 const v8::PropertyCallbackInfo<void>& info) { | 1926 const v8::PropertyCallbackInfo<void>& info) { |
1927 Handle<Object> self = info.This(); | 1927 Handle<Object> self = Handle<Object>::Cast(info.This()); |
1928 self->Set(String::Concat(v8_str("accessor_"), name), value); | 1928 self->Set(String::Concat(v8_str("accessor_"), name), value); |
1929 } | 1929 } |
1930 | 1930 |
1931 void EmptyInterceptorGetter(Local<String> name, | 1931 void EmptyInterceptorGetter(Local<String> name, |
1932 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1932 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1933 } | 1933 } |
1934 | 1934 |
1935 void EmptyInterceptorSetter(Local<String> name, | 1935 void EmptyInterceptorSetter(Local<String> name, |
1936 Local<Value> value, | 1936 Local<Value> value, |
1937 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1937 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1938 } | 1938 } |
1939 | 1939 |
1940 void InterceptorGetter(Local<String> name, | 1940 void InterceptorGetter(Local<String> name, |
1941 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1941 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1942 // Intercept names that start with 'interceptor_'. | 1942 // Intercept names that start with 'interceptor_'. |
1943 String::Utf8Value utf8(name); | 1943 String::Utf8Value utf8(name); |
1944 char* name_str = *utf8; | 1944 char* name_str = *utf8; |
1945 char prefix[] = "interceptor_"; | 1945 char prefix[] = "interceptor_"; |
1946 int i; | 1946 int i; |
1947 for (i = 0; name_str[i] && prefix[i]; ++i) { | 1947 for (i = 0; name_str[i] && prefix[i]; ++i) { |
1948 if (name_str[i] != prefix[i]) return; | 1948 if (name_str[i] != prefix[i]) return; |
1949 } | 1949 } |
1950 Handle<Object> self = info.This(); | 1950 Handle<Object> self = Handle<Object>::Cast(info.This()); |
1951 info.GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i))); | 1951 info.GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i))); |
1952 } | 1952 } |
1953 | 1953 |
1954 void InterceptorSetter(Local<String> name, | 1954 void InterceptorSetter(Local<String> name, |
1955 Local<Value> value, | 1955 Local<Value> value, |
1956 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1956 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1957 // Intercept accesses that set certain integer values, for which the name does | 1957 // Intercept accesses that set certain integer values, for which the name does |
1958 // not start with 'accessor_'. | 1958 // not start with 'accessor_'. |
1959 String::Utf8Value utf8(name); | 1959 String::Utf8Value utf8(name); |
1960 char* name_str = *utf8; | 1960 char* name_str = *utf8; |
1961 char prefix[] = "accessor_"; | 1961 char prefix[] = "accessor_"; |
1962 int i; | 1962 int i; |
1963 for (i = 0; name_str[i] && prefix[i]; ++i) { | 1963 for (i = 0; name_str[i] && prefix[i]; ++i) { |
1964 if (name_str[i] != prefix[i]) break; | 1964 if (name_str[i] != prefix[i]) break; |
1965 } | 1965 } |
1966 if (!prefix[i]) return; | 1966 if (!prefix[i]) return; |
1967 | 1967 |
1968 if (value->IsInt32() && value->Int32Value() < 10000) { | 1968 if (value->IsInt32() && value->Int32Value() < 10000) { |
1969 Handle<Object> self = info.This(); | 1969 Handle<Object> self = Handle<Object>::Cast(info.This()); |
1970 self->SetHiddenValue(name, value); | 1970 self->SetHiddenValue(name, value); |
1971 info.GetReturnValue().Set(value); | 1971 info.GetReturnValue().Set(value); |
1972 } | 1972 } |
1973 } | 1973 } |
1974 | 1974 |
1975 void AddAccessor(Handle<FunctionTemplate> templ, | 1975 void AddAccessor(Handle<FunctionTemplate> templ, |
1976 Handle<String> name, | 1976 Handle<String> name, |
1977 v8::AccessorGetterCallback getter, | 1977 v8::AccessorGetterCallback getter, |
1978 v8::AccessorSetterCallback setter) { | 1978 v8::AccessorSetterCallback setter) { |
1979 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); | 1979 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); |
(...skipping 6218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8198 static void YGetter(Local<String> name, | 8198 static void YGetter(Local<String> name, |
8199 const v8::PropertyCallbackInfo<v8::Value>& info) { | 8199 const v8::PropertyCallbackInfo<v8::Value>& info) { |
8200 ApiTestFuzzer::Fuzz(); | 8200 ApiTestFuzzer::Fuzz(); |
8201 info.GetReturnValue().Set(v8_num(10)); | 8201 info.GetReturnValue().Set(v8_num(10)); |
8202 } | 8202 } |
8203 | 8203 |
8204 | 8204 |
8205 static void YSetter(Local<String> name, | 8205 static void YSetter(Local<String> name, |
8206 Local<Value> value, | 8206 Local<Value> value, |
8207 const v8::PropertyCallbackInfo<void>& info) { | 8207 const v8::PropertyCallbackInfo<void>& info) { |
8208 if (info.This()->Has(name)) { | 8208 Local<Object> this_obj = Local<Object>::Cast(info.This()); |
8209 info.This()->Delete(name); | 8209 if (this_obj->Has(name)) this_obj->Delete(name); |
8210 } | 8210 this_obj->Set(name, value); |
8211 info.This()->Set(name, value); | |
8212 } | 8211 } |
8213 | 8212 |
8214 | 8213 |
8215 THREADED_TEST(DeleteAccessor) { | 8214 THREADED_TEST(DeleteAccessor) { |
8216 v8::Isolate* isolate = CcTest::isolate(); | 8215 v8::Isolate* isolate = CcTest::isolate(); |
8217 v8::HandleScope scope(isolate); | 8216 v8::HandleScope scope(isolate); |
8218 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 8217 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
8219 obj->SetAccessor(v8_str("y"), YGetter, YSetter); | 8218 obj->SetAccessor(v8_str("y"), YGetter, YSetter); |
8220 LocalContext context; | 8219 LocalContext context; |
8221 v8::Handle<v8::Object> holder = obj->NewInstance(); | 8220 v8::Handle<v8::Object> holder = obj->NewInstance(); |
(...skipping 3229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11451 " result += o.y;" | 11450 " result += o.y;" |
11452 "}" | 11451 "}" |
11453 "result;", | 11452 "result;", |
11454 42 * 10); | 11453 42 * 10); |
11455 } | 11454 } |
11456 | 11455 |
11457 | 11456 |
11458 static void SetOnThis(Local<String> name, | 11457 static void SetOnThis(Local<String> name, |
11459 Local<Value> value, | 11458 Local<Value> value, |
11460 const v8::PropertyCallbackInfo<void>& info) { | 11459 const v8::PropertyCallbackInfo<void>& info) { |
11461 info.This()->ForceSet(name, value); | 11460 Local<Object>::Cast(info.This())->ForceSet(name, value); |
11462 } | 11461 } |
11463 | 11462 |
11464 | 11463 |
11465 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { | 11464 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { |
11466 v8::Isolate* isolate = CcTest::isolate(); | 11465 v8::Isolate* isolate = CcTest::isolate(); |
11467 v8::HandleScope scope(isolate); | 11466 v8::HandleScope scope(isolate); |
11468 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 11467 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11469 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11468 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11470 templ->SetAccessor(v8_str("y"), Return239Callback); | 11469 templ->SetAccessor(v8_str("y"), Return239Callback); |
11471 LocalContext context; | 11470 LocalContext context; |
(...skipping 7066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18538 info.GetReturnValue().Set(v8_num(42)); | 18537 info.GetReturnValue().Set(v8_num(42)); |
18539 } | 18538 } |
18540 | 18539 |
18541 | 18540 |
18542 static void SetterWhichSetsYOnThisTo23( | 18541 static void SetterWhichSetsYOnThisTo23( |
18543 Local<String> name, | 18542 Local<String> name, |
18544 Local<Value> value, | 18543 Local<Value> value, |
18545 const v8::PropertyCallbackInfo<void>& info) { | 18544 const v8::PropertyCallbackInfo<void>& info) { |
18546 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18545 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18547 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18546 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18548 info.This()->Set(v8_str("y"), v8_num(23)); | 18547 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
18549 } | 18548 } |
18550 | 18549 |
18551 | 18550 |
18552 void FooGetInterceptor(Local<String> name, | 18551 void FooGetInterceptor(Local<String> name, |
18553 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18552 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18554 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18553 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18555 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18554 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18556 if (!name->Equals(v8_str("foo"))) return; | 18555 if (!name->Equals(v8_str("foo"))) return; |
18557 info.GetReturnValue().Set(v8_num(42)); | 18556 info.GetReturnValue().Set(v8_num(42)); |
18558 } | 18557 } |
18559 | 18558 |
18560 | 18559 |
18561 void FooSetInterceptor(Local<String> name, | 18560 void FooSetInterceptor(Local<String> name, |
18562 Local<Value> value, | 18561 Local<Value> value, |
18563 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18562 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18564 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18563 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18565 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18564 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18566 if (!name->Equals(v8_str("foo"))) return; | 18565 if (!name->Equals(v8_str("foo"))) return; |
18567 info.This()->Set(v8_str("y"), v8_num(23)); | 18566 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
18568 info.GetReturnValue().Set(v8_num(23)); | 18567 info.GetReturnValue().Set(v8_num(23)); |
18569 } | 18568 } |
18570 | 18569 |
18571 | 18570 |
18572 TEST(SetterOnConstructorPrototype) { | 18571 TEST(SetterOnConstructorPrototype) { |
18573 v8::Isolate* isolate = CcTest::isolate(); | 18572 v8::Isolate* isolate = CcTest::isolate(); |
18574 v8::HandleScope scope(isolate); | 18573 v8::HandleScope scope(isolate); |
18575 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18574 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18576 templ->SetAccessor(v8_str("x"), | 18575 templ->SetAccessor(v8_str("x"), |
18577 GetterWhichReturns42, | 18576 GetterWhichReturns42, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18610 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18609 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18611 info.GetReturnValue().Set(v8_num(42)); | 18610 info.GetReturnValue().Set(v8_num(42)); |
18612 } | 18611 } |
18613 | 18612 |
18614 | 18613 |
18615 static void NamedPropertySetterWhichSetsYOnThisTo23( | 18614 static void NamedPropertySetterWhichSetsYOnThisTo23( |
18616 Local<String> name, | 18615 Local<String> name, |
18617 Local<Value> value, | 18616 Local<Value> value, |
18618 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18617 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18619 if (name->Equals(v8_str("x"))) { | 18618 if (name->Equals(v8_str("x"))) { |
18620 info.This()->Set(v8_str("y"), v8_num(23)); | 18619 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
18621 } | 18620 } |
18622 } | 18621 } |
18623 | 18622 |
18624 | 18623 |
18625 THREADED_TEST(InterceptorOnConstructorPrototype) { | 18624 THREADED_TEST(InterceptorOnConstructorPrototype) { |
18626 v8::Isolate* isolate = CcTest::isolate(); | 18625 v8::Isolate* isolate = CcTest::isolate(); |
18627 v8::HandleScope scope(isolate); | 18626 v8::HandleScope scope(isolate); |
18628 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18627 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18629 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, | 18628 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, |
18630 NamedPropertySetterWhichSetsYOnThisTo23); | 18629 NamedPropertySetterWhichSetsYOnThisTo23); |
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22492 v8::internal::FLAG_stack_size = 150; | 22491 v8::internal::FLAG_stack_size = 150; |
22493 LocalContext current; | 22492 LocalContext current; |
22494 v8::Isolate* isolate = current->GetIsolate(); | 22493 v8::Isolate* isolate = current->GetIsolate(); |
22495 v8::HandleScope scope(isolate); | 22494 v8::HandleScope scope(isolate); |
22496 V8::SetCaptureStackTraceForUncaughtExceptions( | 22495 V8::SetCaptureStackTraceForUncaughtExceptions( |
22497 true, 10, v8::StackTrace::kDetailed); | 22496 true, 10, v8::StackTrace::kDetailed); |
22498 v8::TryCatch try_catch; | 22497 v8::TryCatch try_catch; |
22499 CompileRun("(function f(x) { f(x+1); })(0)"); | 22498 CompileRun("(function f(x) { f(x+1); })(0)"); |
22500 CHECK(try_catch.HasCaught()); | 22499 CHECK(try_catch.HasCaught()); |
22501 } | 22500 } |
OLD | NEW |