OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); | 195 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); |
196 CompileRun( | 196 CompileRun( |
197 "var o = new UnrelFun();" | 197 "var o = new UnrelFun();" |
198 "o.m = Fun.prototype.m;" | 198 "o.m = Fun.prototype.m;" |
199 "o.m();"); | 199 "o.m();"); |
200 CHECK_EQ(2, signature_callback_count); | 200 CHECK_EQ(2, signature_callback_count); |
201 CHECK(try_catch.HasCaught()); | 201 CHECK(try_catch.HasCaught()); |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 | |
206 | |
207 THREADED_TEST(ArgumentSignature) { | 205 THREADED_TEST(ArgumentSignature) { |
208 v8::HandleScope scope; | 206 v8::HandleScope scope; |
209 LocalContext env; | 207 LocalContext env; |
210 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); | 208 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); |
211 cons->SetClassName(v8_str("Cons")); | 209 cons->SetClassName(v8_str("Cons")); |
212 v8::Handle<v8::Signature> sig = | 210 v8::Handle<v8::Signature> sig = |
213 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons); | 211 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons); |
214 v8::Handle<v8::FunctionTemplate> fun = | 212 v8::Handle<v8::FunctionTemplate> fun = |
215 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig); | 213 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig); |
216 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); | 214 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); |
(...skipping 13687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13904 CHECK(func2->CreationContext() == context2); | 13902 CHECK(func2->CreationContext() == context2); |
13905 CheckContextId(func2, 2); | 13903 CheckContextId(func2, 2); |
13906 CHECK(instance2->CreationContext() == context2); | 13904 CHECK(instance2->CreationContext() == context2); |
13907 CheckContextId(instance2, 2); | 13905 CheckContextId(instance2, 2); |
13908 } | 13906 } |
13909 | 13907 |
13910 context1.Dispose(); | 13908 context1.Dispose(); |
13911 context2.Dispose(); | 13909 context2.Dispose(); |
13912 context3.Dispose(); | 13910 context3.Dispose(); |
13913 } | 13911 } |
13912 | |
13913 | |
13914 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, | |
13915 const AccessorInfo& info) { | |
13916 if (index == 42) return v8_str("yes"); | |
13917 return Handle<v8::Integer>(); | |
13918 } | |
13919 | |
13920 | |
13921 Handle<Value> HasOwnPropertyNamedPropertyGetter(Local<String> property, | |
13922 const AccessorInfo& info) { | |
13923 if (property->Equals(v8_str("foo"))) return v8_str("yes"); | |
13924 return Handle<Value>(); | |
13925 } | |
13926 | |
13927 | |
13928 Handle<v8::Integer> HasOwnPropertyIndexedPropertyQuery( | |
13929 uint32_t index, const AccessorInfo& info) { | |
13930 if (index == 42) return v8_num(1).As<v8::Integer>(); | |
13931 return Handle<v8::Integer>(); | |
13932 } | |
13933 | |
13934 | |
13935 Handle<v8::Integer> HasOwnPropertyNamedPropertyQuery( | |
13936 Local<String> property, const AccessorInfo& info) { | |
13937 if (property->Equals(v8_str("foo"))) return v8_num(1).As<v8::Integer>(); | |
13938 return Handle<v8::Integer>(); | |
13939 } | |
13940 | |
13941 | |
13942 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property, | |
13943 const AccessorInfo& info) { | |
13944 return v8_str("yes"); | |
13945 } | |
13946 | |
13947 | |
13948 TEST(HasOwnProperty) { | |
13949 v8::HandleScope scope; | |
13950 LocalContext env; | |
13951 { // Check normal properties and defined getters. | |
13952 Handle<Value> value = CompileRun( | |
13953 "function Foo() {" | |
13954 " this.foo = 11;" | |
13955 " this.__defineGetter__('baz', function() { return 1; });" | |
13956 "};" | |
13957 "function Bar() { " | |
13958 " this.bar = 13;" | |
13959 " this.__defineGetter__('bla', function() { return 2; });" | |
13960 "};" | |
13961 "Bar.prototype = new Foo();" | |
13962 "new Bar();"); | |
13963 CHECK(value->IsObject()); | |
13964 Handle<Object> object = value->ToObject(); | |
13965 CHECK(object->Has(v8_str("foo"))); | |
13966 CHECK(!object->HasOwnProperty(v8_str("foo"))); | |
13967 CHECK(object->HasOwnProperty(v8_str("bar"))); | |
13968 CHECK(object->Has(v8_str("baz"))); | |
13969 CHECK(!object->HasOwnProperty(v8_str("baz"))); | |
13970 CHECK(object->HasOwnProperty(v8_str("bla"))); | |
13971 } | |
13972 { // Check named getter interceptors. | |
13973 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | |
13974 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); | |
13975 Handle<Object> instance = templ->NewInstance(); | |
13976 CHECK(!instance->HasOwnProperty(v8_str("42"))); | |
13977 CHECK(instance->HasOwnProperty(v8_str("foo"))); | |
13978 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | |
13979 } | |
13980 { // Check indexed getter interceptors. | |
13981 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | |
13982 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); | |
13983 Handle<Object> instance = templ->NewInstance(); | |
13984 CHECK(instance->HasOwnProperty(v8_str("42"))); | |
13985 CHECK(!instance->HasOwnProperty(v8_str("43"))); | |
13986 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | |
13987 } | |
13988 { // Check named query interceptors. | |
13989 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | |
13990 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); | |
Mads Ager (chromium)
2011/04/28 08:38:27
Maybe add a case with interceptor getters and inte
| |
13991 Handle<Object> instance = templ->NewInstance(); | |
13992 CHECK(instance->HasOwnProperty(v8_str("foo"))); | |
13993 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | |
13994 } | |
13995 { // Check indexed query interceptors. | |
13996 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | |
13997 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); | |
13998 Handle<Object> instance = templ->NewInstance(); | |
13999 CHECK(instance->HasOwnProperty(v8_str("42"))); | |
14000 CHECK(!instance->HasOwnProperty(v8_str("41"))); | |
14001 } | |
14002 { // Check callbacks. | |
14003 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | |
14004 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); | |
14005 Handle<Object> instance = templ->NewInstance(); | |
14006 CHECK(instance->HasOwnProperty(v8_str("foo"))); | |
14007 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | |
14008 } | |
14009 } | |
OLD | NEW |