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

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

Issue 6903059: Expose hasOwnProperty() through API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add one more test. Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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<v8::Integer> HasOwnPropertyNamedPropertyQuery2(
13943 Local<String> property, const AccessorInfo& info) {
13944 if (property->Equals(v8_str("bar"))) return v8_num(1).As<v8::Integer>();
13945 return Handle<v8::Integer>();
13946 }
13947
13948
13949 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property,
13950 const AccessorInfo& info) {
13951 return v8_str("yes");
13952 }
13953
13954
13955 TEST(HasOwnProperty) {
13956 v8::HandleScope scope;
13957 LocalContext env;
13958 { // Check normal properties and defined getters.
13959 Handle<Value> value = CompileRun(
13960 "function Foo() {"
13961 " this.foo = 11;"
13962 " this.__defineGetter__('baz', function() { return 1; });"
13963 "};"
13964 "function Bar() { "
13965 " this.bar = 13;"
13966 " this.__defineGetter__('bla', function() { return 2; });"
13967 "};"
13968 "Bar.prototype = new Foo();"
13969 "new Bar();");
13970 CHECK(value->IsObject());
13971 Handle<Object> object = value->ToObject();
13972 CHECK(object->Has(v8_str("foo")));
13973 CHECK(!object->HasOwnProperty(v8_str("foo")));
13974 CHECK(object->HasOwnProperty(v8_str("bar")));
13975 CHECK(object->Has(v8_str("baz")));
13976 CHECK(!object->HasOwnProperty(v8_str("baz")));
13977 CHECK(object->HasOwnProperty(v8_str("bla")));
13978 }
13979 { // Check named getter interceptors.
13980 Handle<ObjectTemplate> templ = ObjectTemplate::New();
13981 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter);
13982 Handle<Object> instance = templ->NewInstance();
13983 CHECK(!instance->HasOwnProperty(v8_str("42")));
13984 CHECK(instance->HasOwnProperty(v8_str("foo")));
13985 CHECK(!instance->HasOwnProperty(v8_str("bar")));
13986 }
13987 { // Check indexed getter interceptors.
13988 Handle<ObjectTemplate> templ = ObjectTemplate::New();
13989 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter);
13990 Handle<Object> instance = templ->NewInstance();
13991 CHECK(instance->HasOwnProperty(v8_str("42")));
13992 CHECK(!instance->HasOwnProperty(v8_str("43")));
13993 CHECK(!instance->HasOwnProperty(v8_str("foo")));
13994 }
13995 { // Check named query interceptors.
13996 Handle<ObjectTemplate> templ = ObjectTemplate::New();
13997 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery);
13998 Handle<Object> instance = templ->NewInstance();
13999 CHECK(instance->HasOwnProperty(v8_str("foo")));
14000 CHECK(!instance->HasOwnProperty(v8_str("bar")));
14001 }
14002 { // Check indexed query interceptors.
14003 Handle<ObjectTemplate> templ = ObjectTemplate::New();
14004 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery);
14005 Handle<Object> instance = templ->NewInstance();
14006 CHECK(instance->HasOwnProperty(v8_str("42")));
14007 CHECK(!instance->HasOwnProperty(v8_str("41")));
14008 }
14009 { // Check callbacks.
14010 Handle<ObjectTemplate> templ = ObjectTemplate::New();
14011 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter);
14012 Handle<Object> instance = templ->NewInstance();
14013 CHECK(instance->HasOwnProperty(v8_str("foo")));
14014 CHECK(!instance->HasOwnProperty(v8_str("bar")));
14015 }
14016 { // Check that query wins on disagreement.
14017 Handle<ObjectTemplate> templ = ObjectTemplate::New();
14018 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter,
14019 0,
14020 HasOwnPropertyNamedPropertyQuery2);
14021 Handle<Object> instance = templ->NewInstance();
14022 CHECK(!instance->HasOwnProperty(v8_str("foo")));
14023 CHECK(instance->HasOwnProperty(v8_str("bar")));
14024 }
14025 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698